Quote:
Originally Posted by ramram29
Don't use a variable. I don't think you can set variables remotely. Try this:
ssh deployer@192.168.0.104 kill $(ps -ef | grep top | awk '{ print $2}' | head -1)
|
Thanks for the response. I gave your suggestion a shot, and the command seems to be looking locally instead of remotely. It fails with:
Code:
bash: line 0: kill: (8029) - No such process
Looking at the pid sequence on the local and remote machines, it looks like a pid from the local machine.
I tried using backticks instead of $() and this string simply getting the PID works:
Code:
ssh deployer@192.168.0.104 ``ps -ef | grep top | awk '{ print $2}' | head -1``
However when I try adding the kill command (sudo kill, since I'm not connecting as root) I get the following:
Code:
ssh deployer@192.168.0.104 sudo kill ``ps -ef | grep top | awk '{ print $2}' | head -1``
Password:********
kill: can't find process "ps"
kill: can't find process "-ef"
I think I found a very hurky way of doing this, but it isn't pretty. I tried running the remote grep for the PID and writing it to a file, hoping then I could use command sub to write the PID into a variable. Unfortunately, it writes the file locally, not on the remote machine. So I tried scp'ing the file to the remote machine, then use command sub to put the PID into a variable and use that variable to run kill:
Code:
ssh deployer@192.168.0.104 ``ps -ef | grep top | awk '{ print $2}' | head -1`` > process.pidfile
scp process.pidfile deployer@192.168.0.104:
ssh deployer@192.168.0.104 'ERPMPROC=`cat process.pidfile`; sudo kill $ERPMPROC'
This seems to work, but it introduces some complexity I'd rather not have. If you have any other suggestions on getting other options to work, I'd appreciate it...