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.