SSH starting nohup'd process - not exiting


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting SSH starting nohup'd process - not exiting
# 1  
Old 08-05-2005
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 process needs to be started. It seems that it's a limitation of ksh that you get a report of background processes running when you exit from the shell.

code:

if [ ${running} -eq 0 -o ${newdate} -eq 0 ];then
nohup ${bin_base}/${stream}/bin/xacct_viewlog Gatherer 500 >> ${stream_home}/${logfilename} &
echo " I have restarted with process ID: $!"
echo $! > ${pid_file}
echo $currentdate > ${datefile}
echo " Exiting having restarted ..."
fi


so far so good, this works fine when run as a shell script from the command line on the box.

When I run it from a remote host using the following script:

package_list="server1 server2 server3"

kick_me ()
{
set -x
server=$1
for stream in $stream_list
do
ssh -q $server -l xacct /var/tmp/oas_xacct_log_flatten.sh $stream
done
}

for server in $package_list
do
case "$server" in
medG1oat|medG1)
stream_list="stream1 stream2 stream3"
kick_me $server
;;

esac
done

I have simplified this script but it loops through several clients and several streams on each client running the shell script on the remote client to kick off the background process. The problem is that when it gets to the first process it actually has to start (the script checks to see if an instance of itself is already running and if it is already running it goes onto the next in the loop) then it kicks off the process and sits there. Looking through the man pages for ksh it seems that the shell won't detach while there are running jobs despite the job being kicked off as nohup. I have tried changing the code on the client playing with and without nohup etc and no joy.

Any ideas?

I leave this contract at 4pm to emigrate to Australia so this is mainly for the benefit of my boss (he's actually a good bloke) but it grinds my privates that i cannot solve this.
# 2  
Old 02-20-2008
any luck

did you ever receive a solution to this problem ? i'm having a very similar problem.
# 3  
Old 06-17-2009
redirecting input

You have to redirect input of the nohup'd process (</dev/null).

The ssh connects the local terminal's input/output/error with the remote process. So it won't release the connection until any process on the remote side holds a reference to the local input (and maybe output/error as well but I cannot confirm this).
# 4  
Old 06-17-2009
Try "-n" switch to ssh. This is actually the same issue as described in the post from "sendchar".
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ssh - running remote command not exiting

Hi, i have a shellscript, where in i need to connect to different server start these three jobs and exit from the server and start the same three jobs on local server. ssh user@remotehost 'bash -s' << EOF ${GETT_HOME}/bin/start1 & sleep 10 ${GETT_HOME}/bin/start2 & sleep 10... (1 Reply)
Discussion started by: swapnabhargav
1 Replies

2. Shell Programming and Scripting

Process with tee is not exiting out

Hi I have a script which we are calling as below from another script but it does not exit out and just hang there. main.ksh #!/bin.ksh echo "test1" test.ksh | tee /tmp/abc.txt echo "test2" it prints test1 and then just hangs on test.ksh | tee /tmp/abc.txt if i check the messages from... (3 Replies)
Discussion started by: reldb
3 Replies

3. AIX

How to kill exiting process in AIX

I could not able to kill two process which is running in the required port for me.Can any body help me to kill the exiting process. - 27000908 - - - <exiting> - 30998528 - - - <exiting> (8 Replies)
Discussion started by: sasikanta
8 Replies

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

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

[KSH/Bash] Starting a parent process from a child process?

Hey all, I need to launch a script from within 2 other scripts that can run independently of the two parent scripts... Im having a hard time doing this, if anyone knows how please let me know. More detail. ScriptA (bash), ScriptB (ksh), ScriptC (bash) ScriptA, launches ScriptB ScirptB,... (7 Replies)
Discussion started by: trey85stang
7 Replies

7. Shell Programming and Scripting

How to starting process as daemon using ssh command?

Hello, I need to run a command on remote Linux using the ssh command from my local machine. I am able to execute the command on remote machine using ssh but it's behaving strangely. The command is supposed to start a daemon process on remote linux box and the control should return back to me... (5 Replies)
Discussion started by: nitinshukla
5 Replies

8. Shell Programming and Scripting

pid of nohup process

I want to print the pid of a nohup process to a file so later I can use the list of pid's in that file to stop the background processes again. I use ksh on AIXv5.3: nohup /start/script.ksh 1>/dev/null 2>&1 print $$ > .pid nohup /start/script2.ksh 1>/dev/null 2>&1 print $$ >> .pid But... (2 Replies)
Discussion started by: rein
2 Replies

9. UNIX for Dummies Questions & Answers

Exiting eXceed window kills my process

Hi, I run a binary application with GUI accessibility. To launch and close the application i follow the following steps: 1.Log into a console session. Export display to the local workstation. 2.Launch X windows app ( eXceed ) 3.From terminal session go to the my application directory and... (2 Replies)
Discussion started by: shantaputi
2 Replies

10. Shell Programming and Scripting

capture the process id when starting a background process

Hello all, How do I start a background process and save the process id to a file on my system. For example %wait 5 & will execute and print the process id. I can't figure out how to get it to a file. I've tried: > filename 0>filename 1>filename. Any assistance is most appreciated. Thanks, Jim... (10 Replies)
Discussion started by: jleavitt
10 Replies
Login or Register to Ask a Question