LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-06-2008, 06:38 PM   #1
babag
Member
 
Registered: Aug 2003
Posts: 419

Rep: Reputation: 31
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

Last edited by babag; 04-06-2008 at 06:41 PM.
 
Old 04-06-2008, 06:48 PM   #2
blacky_5251
Member
 
Registered: Oct 2004
Location: Adelaide Hills, South Australia
Distribution: RHEL 5&6 CentOS 5, 6 & 7
Posts: 573

Rep: Reputation: 61
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.

Last edited by blacky_5251; 04-06-2008 at 06:52 PM.
 
Old 04-06-2008, 11:18 PM   #3
babag
Member
 
Registered: Aug 2003
Posts: 419

Original Poster
Rep: Reputation: 31
thanks again, ian. once again, very helpful. will try
this tomorrow when i get back to those stations.

BabaG
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to monitor a running script initiated from remote computer babag Programming 3 04-07-2008 03:11 PM
running script on a remote host p_test Programming 5 10-02-2006 03:40 PM
How do you connect to another computer and use an application running on it remote? zahadumy Linux - Software 8 05-19-2006 04:43 PM
Running a script in background on a remote machine TheCoffeeMug Linux - Networking 3 11-06-2003 10:08 AM
run programs on a remote computer with script, how? cmisip Linux - Networking 5 07-07-2003 01:48 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:46 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration