scripting - Bash - output of command seems to be an integer but "[" complains -


i checking see if process on remote server has been killed. 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 ]    echo "pipeline stopped successfully"   exit 0 else   echo "pipeline not stopped successfully"   exit 1 fi 

however when execute get:

    : integer expression expected pipeline not stopped 1 

the actual value returned "1" no whitespace. checked by:

vim <(ssh -t -t -i id_dsa headless@remoteserver.com "ps -auxwww |grep pipeline| wc -l" | sed -e 's/^[ \t]*//') 

and ":set list" showed integer , line feed returned value.

i'm @ loss here why not working.

if output of ssh command integer preceded optional tabs, shouldn't need sed command; shell strip leading and/or trailing whitespace unnecessary before using operand -lt operator.

if [ $(ssh -tti id_dsa headless@remoteserver.com "ps -auxwww | grep -c pipeline") -lt 3 ]; 

it possible result of ssh not same when run manually when runs in shell. might try saving in variable can output before testing in script:

result=$( ssh -tti id_dsa headless@remoteserver.com "ps -auxwww | grep -c pipeline" ) if [ $result -lt 3 ]; 

Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -