ssh a nohup command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ssh a nohup command
# 1  
Old 12-01-2010
ssh a nohup command

I have a script I'm creating to spawn netcat listeners on a remote server for copying files at high speeds. The issue I'm running into is that after running the "nohup nc -l -p 12345 | tar -xvf - &" commands I can't get the remote shell to terminate. I'm not sure if this is working as intended or I'm missing something, but a simple test can reproduce the same results:

At a bash shell run the following:

nohup sleep 1000 &

exit

The shell clears screen and hangs until the sleep process is killed or finishes. If you check the process though you can see the shell is no longer the parent process:

[root@test ~]# ps -fea |grep sleep |grep -v grep
root 6990 1 0 12:15 ? 00:00:00 sleep 1000

So, beyond having a comment in my script to have users "ctrl-c" to continue, does anyone have a more elegant solution to kill the shell on the remote server?

Last edited by headcr4sh; 12-01-2010 at 05:22 PM..
# 2  
Old 12-01-2010
Try the at command:
Code:
ssh me@remotenode 'at now <<!
some command that takes a long time 
!
'

note the last ' on a line by itself...

If users are going to buzz bomb the remote node with this command you need to modify the /etc/crond.d/queuedefs file to set the at queue to a larger size and to a nice value.
Note queuedefs is in different places/different names on different boxes. It usually lives with at.deny.

Also, the user account for the ssh needs "at" privileges
# 3  
Old 12-01-2010
Worked like a charm. Thanks Jim!

Code:
 
ssh user@test 'at now <<ENDOFSSH
nc -l -p 12345 | tar -xvf - 
ENDOFSSH
'


Last edited by headcr4sh; 12-01-2010 at 05:22 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Background (nohup * &) SSH command block possible?

Hello, I am trying to find a way to send several sequential commands via SSH to a remote box in a single command. Thoughts so far: 1) Can I put them into a function and call the function within the ssh command? e.g. ssh <targetserver> $(functionx) No - then it calls the function in... (4 Replies)
Discussion started by: doonan_79
4 Replies

2. Shell Programming and Scripting

ssh -t and nohup

I have a fairly simple script like so: nohup java -jar program.jar >> log 2>&1 & echo $! > pidfile This works great when using ssh server "script.sh" but not when using ssh -t server "script.sh" The solution I came up with was to call sleep after recording the child pid. My guess at the... (2 Replies)
Discussion started by: croachrose
2 Replies

3. AIX

Nohup command

I'm trying to run a compress script in the background, but I even though the script is running in the background I get "Sending nohup output to nohup.out." and the screen just stays there. How can I make the script run in background and make my command prompt come back. I was using: nohup... (2 Replies)
Discussion started by: NycUnxer
2 Replies

4. Shell Programming and Scripting

SSH starting nohup'd process - not exiting

I'm trying to ssh into a remote server, run a script which may or may not start a nohup'd background process and then exit leaving the process running on the remote server. I'm looping through a number of servers to do this but the script hangs as soon as it comes to a server where the remote... (3 Replies)
Discussion started by: Steve_H
3 Replies

5. UNIX for Dummies Questions & Answers

nohup command..

Hi.. Can anybody tell me, what exactly the nohup command does & when is it used? Your help is appreciated. (3 Replies)
Discussion started by: Amol21
3 Replies

6. Shell Programming and Scripting

nohup command in the script....

I want to know how to use a nohup command in the script........ I have to run following command nohup /tmp/app/statuscheck.sh & After typing this command I will type ctrl D to come to the prompt and the that command will run in backround. Even after pressing & the command is not... (3 Replies)
Discussion started by: jayaramanit
3 Replies

7. UNIX for Dummies Questions & Answers

Problem with nohup command

Hello folks, I have got a script which telnets to different boxes and runs a certain script with 3 run time args. The line from the script which does it is: (sleep 1; echo $USERID ; sleep 1; echo $PASSWD ; sleep 1 ; echo y ; sleep 1 ; echo "\r" ; sleep 1 ; echo "cd $FILEPATH" ; sleep 1 ; sleep 1... (1 Reply)
Discussion started by: Rajat
1 Replies

8. Shell Programming and Scripting

nohup command o/p redirection

Hi I am using nohup command in script(say nohup ls- ltr > somefile 2>&1 & ). I dont want any kind of output to be displayed on screen. When i tried the above nohup it still gives me some out put on screen like 2991 Done >somefile 2>&1 Please you let me know what is... (3 Replies)
Discussion started by: ammu
3 Replies

9. Shell Programming and Scripting

What's the command for nohup in Oracle

Hello, I need running the process from Oracle in backround. Thank you for your help. C.Abarca (1 Reply)
Discussion started by: cabarcaj
1 Replies

10. UNIX for Dummies Questions & Answers

Nohup Command

Hello All, I am newbie to unix.I am trying to use NOHUP command in shell script it works fine with only "nohup test.sh 10 &" and "/opt/user/nohup test.sh 10 &" gives an error saying "ksh: /opt/user/nohup : not found". Can anybody please guide me to make it work. Thanks Blazix (9 Replies)
Discussion started by: blazix
9 Replies
Login or Register to Ask a Question