PID missing on my File.

I have 3 files namely run1.cmd, run2.cmd & run3.cmd

more run1.cmd

cd /tmp/scripts/app1/
nohup ./startserver.sh &

more run2.cmd

cd /tmp/scripts/app2/
nohup ./startserver.sh &

more run3.cmd

cd /tmp/scripts/app3/
nohup ./startserver.sh &

These scripts are kept on my [Linux] ansible server [SERVER-A]

I wish to execute these scripts executeall.sh from [SERVER-A] onto a remote Solaris server [SERVER-B] using ansible [ssh] tool like below.

more executeall.sh
./run1.cmd
./run2.cmd
./run3.cmd

After execution from SERVER-A i go to SERVER-B to check if the process is running.

On SERVER-B i see the three process running but strangely the process PID is not logging to nohup.out

fuser /tmp/scripts/app1/nohup.out
No Output

instead the PID is is showing for

fuser /tmp/scripts/app1/startserver.sh
: 23455o

Thus i also do not find any logging happening on nohup.out.

However, when i run the below

./run1.cmd
./run2.cmd
./run3.cmd

directly on SERVER-B i see the nohup.out logging and PID on nohup.out as desired.

Can you please explain why do i see this strange behavior and how can i address this problem ?

It's a feature of some shells to display the job nr and the PID of a started background process.
But the display goes to the terminal, not into the nohup.out.
The nohup.out only gets the output of the ./startserver.sh command.
The PID of the (last) background command can be written to a logfile, for example

echo $! >>logfile

This is a show stopper and only if I could get a feasible solution.

  1. if the PID goes to startserver.sh instead of nohup.out ... that's is fine but why no logging in the nohup.out ?? We need logging to the nohup.out irrespective of whether it is the startserver.sh or the nohup.out that gets the PID.

  2. We need to get the pid of the process inorder to kill it automatically thus we cannot enforce everyone starting our servers to echo $! >>logfile

They may start as they like. Hence fuser of the file name was a feasible option to get the pid and kill it using automation.

Does the remote user have a csh/tcsh login shell?
Then nohup is a builtin - it does not use nohup.out file.
Use /usr/bin/nohup or \nohup to skip a builtin or alias.

1 Like