Execute Script using nohup and &

Hi all,

I have one script test.sh for which I pass two arguments. In the same script I need to submit this script in background using nohup. My script like this and it is working in HP-UX os but not Solaris.

#! /bin/sh

if [ $MTR_PID"0" = "0" ]
then
	MTR_PID=$$
	export MTR_PID
	echo "test.sh $1 $2 $MTR_PID"|xargs nohup |&
fi

if [ $3"0" != "0" -a "$3" = "$MTR_PID" ]
then
        while [ 1 ]
                do
			./Monitor.sh $1
                        sleep $2
                done
fi
exit

Can anyone tell me why this is not getting executed in Solaris?

Thanks,
Sridhar

As you only have a limited number of arguments to your test.sh script I would replace:

echo "test.sh $1 $2 $MTR_PID"|xargs nohup |&

with:

nohup test.sh $1 $2 ${MTR_PID} &

instead, perhaps being a bit simpler it will then behave running on both HP-UX and Solaris?

Also Monitor.sh is preceded with "./" should test.sh also be preceded with "./", which it will need if test.sh is not in the PATH and is in the current directory?

Hi Tony,

Your suggestion worked!! I was not knowing that we can pass arguments while using nohup as well.
Thanks a lot

I kept like this now.

nohup test.sh $1 $2 ${MTR_PID} >> mtr.log 2>> mtr.log </dev/null &

in order to redirect the output and errors to mtr.log. But when this is executed, its still creating nohup.out file with 0 size. How can I avoid the creation of nohup.out file?

Thanks,
Sridhar

I don't know if you can avoid a nohup.out file (except by doing a cd /tmp and then calling your script with a full path so that nohup.out ends in in /tmp?) but I do know that:

>> mtr.log 2>> mtr.log 

can be replaced with:

>> mtr.log 2>&1

The 2>&1 combines stderr with stdout so that both get appended to mtr.log.