Quit a shell script thats running on a remote machine

 
Thread Tools Search this Thread
Operating Systems OS X (Apple) Quit a shell script thats running on a remote machine
# 1  
Old 02-06-2013
Quit a shell script thats running on a remote machine

I'm in a situation where I am executing a shell script(Bash) on another machine remotely using ssh, and for various reasons sometimes need to quit it and restart it. The shell script being run does many different things, so its hard to know what process to kill on the remote machine, and even if I do it will just skip to the next line of the shell script.

At the moment my solution is to just have the remote machine Kill the Terminal. This is a very unsexy solution to me because the remote machine may need to have the terminal open for other reasons and this will end those other processes.

One thing that could be relevant is that I know the name of the terminal window my shell script is being run in. So if I could somehow just kill that specific window and leave the rest open, that would work perfectly.

Any help is much appreciated! -Cheers DD
# 2  
Old 02-06-2013
Very strange design. Do you mean to say that the remote script creates concurrent processes all of which block signals? Some signals cannot be blocked. And once a parent process dies the children are then "inherited" by the init process.

The term you want is session leader or session owner. That is the process which owns the terminal.

Sounds like that script should keep ownership of the children and then respond correctly to a SIGTERM signal - tell the children to die, reap them and exit. What you describe is a little on the pathological side, IMO.

One way to deal with it:
If you do not have pstree, install it with homebrew. pstree will show you the process tree your pathological script has created. This means you can kill off all of the Addams family with
Code:
ssh  me@remotebox 'kill -9 childpid1 childpid2 .... childpidn, parentpid'

BTW
Code:
kill -9

is a last resort, your code really should recognize more standard signals and respond correctly. This kill command does not let the processes shutdown correctly - it just obliterates them - go directly to jail, do not pass Go, do not collect $200.
# 3  
Old 02-07-2013
To me that sounds like the requestor has a terminal session open permanently just to run that script, constantly. If that's the case, wouldn't this be an ideal candidate for a self-sufficient "daemon" script that you kick off - in the terminal, using cron, during boot - and then leave alone running happily, logging its progress to a (system?) file, so you can check what it does, or even mailing you should problems occur.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Keep a script on remote machine running (nohup?)

Hi, I'm using expect to ssh into remote machine (i know its not the best practice), and run script "script.sh". This "script.sh" checks whether an other process (some another script) is running and if not, it runs it as some other user. #!/bin/bash /usr/bin/expect << EOD set... (5 Replies)
Discussion started by: oseri
5 Replies

2. Shell Programming and Scripting

Execute shell script on remote machine

I want to execute a shell script(set of commands) on remote machine and that script takes input from text file(local machine). Please refer below: ssh user@hostname 'bash -s'< ./test.sh file.txt But i got the error file.txt doesn't exist. Can anyone help me on this. Content of test.sh: ... (2 Replies)
Discussion started by: manishtri88
2 Replies

3. UNIX for Dummies Questions & Answers

Execute shell script in remote machine

Hi All, We have 2 servers A and B. B is having a sctipt called b.sh in path /home/dev/scripts. Now my requirement is i want to execute b.sh from server A. Kindly help me. (3 Replies)
Discussion started by: Girish19
3 Replies

4. UNIX for Dummies Questions & Answers

how to use ssh to run shell script on a remote machine?

how to use ssh to run shell script on a remote machine? ssh user@remote sh ./script.unx i ran the above command ./script.unx HAS NOHUP COMMAND IN ITS BODY, I AM GETTING ERROR AS NOHUP NOT FOUND... i tried to run that script from remote server, its working fine do ineed to set... (6 Replies)
Discussion started by: only4satish
6 Replies

5. Shell Programming and Scripting

Running remote system shell script and c binary file from windows machine using java

Hi, I have an shell script program in a remote linux machine which will do some specific monitoring functionality. Also, have some C executables in that machine. From a windows machine, I want to run the shell script program (If possible using java). I tried with SSH for this. but, in... (1 Reply)
Discussion started by: ram.sj
1 Replies

6. Shell Programming and Scripting

executing command in a remote machine through ssh - shell script

Hi All, i have two machines like x and y . my requirement is i should connect to machine Y from x through ssh connection . and do some operation such as copy and move and delete files in Y machine . i tried with this code but it is doing in machine x only . and i need to exit from Y when... (1 Reply)
Discussion started by: rateeshkumar
1 Replies

7. UNIX for Advanced & Expert Users

Script running on remote machine - How ??

Hi All, This was an interview question " There is a clean-up shell-script in one UNIX machine and it is connected to 100 other UNIX machines. Howe can we run the script on all the 100 machines without ftping/copying the script to target machines ? I was unable to answer, please answer if... (5 Replies)
Discussion started by: coolbhai
5 Replies

8. Shell Programming and Scripting

running script in background on remote machine

Hi there I have a script which is running a remote command on hundreds of boxes, it takes around 5 minutes to return an output from this command and because i am running this all from a central box, it goes off to each box in my for loop sequentially meaning that my script will wait for output... (5 Replies)
Discussion started by: hcclnoodles
5 Replies

9. UNIX for Advanced & Expert Users

Running script on remote machine

if i have a script in my system which i need to run on remote system using ssh, how shall i do it? One easy way to to first scp it to remote machine and then run it on remote machine using ssh. Is there any one step way to do it. Preferably one in which i should give password only once (3 Replies)
Discussion started by: vickylife
3 Replies

10. Shell Programming and Scripting

Setting environment variable on a remote solaris machine using shell script

Hi, I am trying to set environment variable on a remote machine. I want to do it by running a shell script Here's what I am doin rsh <remote-hostname> -l root "cd /opt/newclient; . ./setp.sh" In setp.sh, I have ############################# cd ../newlib; export... (1 Reply)
Discussion started by: eamani_sun
1 Replies
Login or Register to Ask a Question