ssh -t and nohup


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ssh -t and nohup
# 1  
Old 05-11-2011
ssh -t and nohup

I have a fairly simple script like so:
Code:
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 problem is that the script and pseudo-tty are destroyed before the child process actually starts. Is there a better way to wait until the child starts before returning? Should I use something other than nohup to ensure the child starts?

I have to use ssh -t because of other constraints.

Last edited by vbe; 05-11-2011 at 09:57 AM.. Reason: please use code tags
# 2  
Old 05-12-2011
What's your shell? You might need the 'disown' command, otherwise, some shells'll try to do job control on the background process and wait for it to quit before it finishes. This doesn't happen without -t because no tty means no job control...
# 3  
Old 05-12-2011
I'm using sh.

---------- Post updated at 07:32 PM ---------- Previous update was at 07:30 PM ----------

Which appears to be dash on the system I'm using.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with nohup

I have a script test1.ksh (Korn shell) and within that I am calling another script test2.ksh test2.ksh runs for a pretty long time and hence wanted to execute as nohup from within test1.ksh nohup ./test2.ksh Question 1) dont think the above is working , although executing the nohup... (1 Reply)
Discussion started by: alldbest
1 Replies

2. Shell Programming and Scripting

Saving nohup output to a file other than nohup.out

Shell : bash OS : Oracle Linux 6.4 I want to save the ouput of a nohup command to file other than nohup.out . Below are my 3 attempts. For both Attempt1 and Attempt2 , the redirection logs the output correctly to the output file. But I get the error "ignoring input and redirecting stderr to... (7 Replies)
Discussion started by: kraljic
7 Replies

3. UNIX for Dummies Questions & Answers

Nohup

Hi Every one , i wrote a script for nohpu ,which checks the service by using the port number and starts if it doesnt hear the port. It works good untill i colse the session. how to make it work even after closing the session .And aslo how to deamoize this script #!/bin/bash netstat -ptlen |... (2 Replies)
Discussion started by: vikatakavi
2 Replies

4. 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

5. Shell Programming and Scripting

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... (2 Replies)
Discussion started by: headcr4sh
2 Replies

6. Shell Programming and Scripting

How to use ssh execute other shell script on other host (shell script include nohup)?

i want use ssh on the host01 to execute autoexec.sh on the host02 like following : host01> ssh host02 autoexec.sh autoexec.sh include nohup command like follwing : nohup /home/jack/deletedata.sh & after i execute ssh host02 autoexec.sh one the host01. i can't found deletedata.sh... (1 Reply)
Discussion started by: orablue
1 Replies

7. UNIX for Dummies Questions & Answers

When we need nohup

Hi, I've read the man page on nohup. But I still can't see what's the differences if we just send a process to background versus sending a nohup process to background. eg: myprocess & vs nohup myprocess & Without nohup, myprocess would still run uninterruptible at background... (2 Replies)
Discussion started by: ehchn1
2 Replies

8. 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

9. UNIX for Dummies Questions & Answers

nohup - help!

I find that if I use nohup (in bourne shell script) then all the interactive parts in my code are gone hidden... e.g., the places asking input from the user (such as ckyorn) will not be displayed. This is no good. Is there a way to use nohup (or similar utility) and meanwhile, to keep the... (9 Replies)
Discussion started by: bluemoon1
9 Replies

10. UNIX for Dummies Questions & Answers

Nohup

Hi, Using nohup it sends output automatically to $HOME/nohup.out - how do I direct this output to another named file instead, so I can run several scripts in the background at once, directing their outputs into individual log files? Cheers (3 Replies)
Discussion started by: miwinter
3 Replies
Login or Register to Ask a Question