using the process status (ps) command in a bash script
Hello,
I was wondering if someone could help me out. I am new to scripting and been working on this bash script for awhile now. I been researching this problem, but I can't seem to find a solution. I was wondering if someone could please help me out. Here is my script: #!/bin/bash NO="ps -ef | grep NO | grep -v grep" NOWC=`ps -ef | grep NO | grep -v grep | wc -l` for CLIENT in $* do ssh $CLIENT -l root "if [ $NOWC -gt 0 ] ; then echo "there are $NOWC processes running" echo "Here is the list of process" eval $NO fi echo "Cannot find that process" echo "Good Bye" exit" done exit 0 Here is the problem. I cannot get this script to run the "ps -ef" command on the client. It get its value from the host machine that I am running this script from. I need this command to execute on the client. When I run the command (ps -ef | grep NO | grep -v grep) on the client, I get something back. Here is what I get when I try to debug the script. XX# ./test_ps5.sh XXXXX + NO='ps -ef | grep NO | grep -v grep' ++ ps -ef ++ grep NO ++ grep -v grep ++ wc -l + NOWC=0 + for CLIENT in '$*' + ssh XXXXX -l root 'if [ 0 -gt 0 ] ; then echo there' are processes 'running echo Here' is the list of 'process eval ps -ef | grep NO | grep -v grep fi echo Cannot' find that 'process echo Good' 'Bye exit' Cannot find that process Good Bye + exit 0 XX# Any input would be appreciated and thank you in advance for your help!! |
I think your quoting is creating problems. Try this:-
Code:
#!/bin/bash |
backquotes are wrong in orig, single quotes above prevent var interpolation; try this
Code:
|
Thank you for your help and suggestions, but for some reason it is still not working. In Blacky's script; the $NOWC variable is still returning a value of zero. Here is the output of Blacky's script in debug mode:
Code:
XX# ./test_ps7.sh XXXXX In Chrism01's script the $CT variable has a value of 0. Here is the output of his script in debug mode: Code:
XX# ./test_ps6.sh XXXXX |
Thanks again for yalls help. I finally got the script to work and here it is:
Code:
#!/bin/bash Thanks again for your help chrism01 and blacky_5251. |
All times are GMT -5. The time now is 02:14 AM. |