LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   killing a running script on remote computer? (https://www.linuxquestions.org/questions/programming-9/killing-a-running-script-on-remote-computer-633539/)

babag 04-06-2008 06:38 PM

killing a running script on remote computer?
 
using a command in a script that looks like this:

ssh <remote computer IP> /home/myaccount/scripts/MyCommand.sh &

this starts a script which loops through a directory
processing photos. the script outputs the filename to
screen for the file it's currently working on.

i can't figure out, since i'm still developing and
testing the scripts, how to kill it once it's started
on the remote computer. tried going to the local box
where the script is running and using:

killall nameofscript.sh

that returned the name of the script and the statement
'no process killed.'

tried giving the full path. same thing.

tried both above as root. same thing.

tried the same thing from the admin box via ssh. same
result. how do i kill this script?


also, i was under the impression that using '&' at the
end of my command line would send the remote script to
the background on my admin box and allow the admin box
to proceed with its own script rather than waiting for
the remote script to finish. this does seem to be the
case but in, to me, an unexpected way. the remote
script, as i say is looping through a directory and
displaying filenames as it works. on my admin box, the
script has moved on past the ssh command to start the
remote script. however, when the remote script moves
on to a new file, that filename flashes up on the
admin box's screen. not horrible. . .yet. if i get a
few boxes all doing this it could get strange to look
at with all of these filenames flashing up as the admin
box is trying to display its own info. how would i
stop this filename flashing? my guess would be by exiting
from the ssh session but wouldn't that command not
execute until the remote script finished? how do i get
out of this one?

thanks,
BabaG

blacky_5251 04-06-2008 06:48 PM

Log on to the remote shell and use "ps" to find the process ID (pid) of the script you want to kill. Perhaps "ps -ef | grep scriptname". Then use "kill -1 pid" to kill the process. If signal 1 doesn't kill it, move through these signal values in this order - 12, 15 and 9.

As for the output, this is expected behaviour. Even though the ssh script has been started in a sub-shell, the output is still being sent to stdout. You need to redirect the output of your ssh script - either in script or on the ssh command line. For example:-
Code:

ssh user@remote scriptname.sh >> /var/log/remote.log 2>&1 &
The >> means Append output to the log file, the 2>&1 means redirect stderr to wherever stdout is going (i.e. the log file), and the final & means in a sub-shell - as you know.

babag 04-06-2008 11:18 PM

thanks again, ian. once again, very helpful. will try
this tomorrow when i get back to those stations.

BabaG


All times are GMT -5. The time now is 09:22 AM.