Operating System - HP-UX
1847340 Members
2413 Online
110264 Solutions
New Discussion

Re: nohup script hanging on second command

 
SOLVED
Go to solution
Clara Rowe
Frequent Advisor

nohup script hanging on second command

Hi Experts! I am by no means a scripting guru and would appreciate some help. The script is suppose to su to a userid and issue a command to run in the background, then su to another userid and do it again. For some reason it hangs when issuing the second su. Here's the script, please help!!!

root@whse370 #> cat START.DET_clara
:

set -vx
killfile=/tmp/kill$$

ps -ef |grep '.sh' > $killfile || exit 1

#
if [ `grep archive_accusort_prdctn.sh "${killfile}" | wc -l ` -eq 0 ]
then `su - spkop -c 'nohup /vol51/spkop/data_conversion/archive_accusort_prdctn.sh >> /vol51/apps/production/logs/spk_prdctn.log 2>&1 &'`
echo "SPK PRODSTAT DATA LOAD HAS BEEN STARTED"
else echo "SPK PRODSTAT DATA LOAD IS ALREADY RUNNING"
fi
#echo "next"
if [ `grep archive_gwl_accusort_prdctn.sh "${killfile}" | wc -l ` -eq 0 ]
then `su - gwlop -c 'nohup /vol51/gwlop/data_conversion/archive_gwl_accusort_prdctn.sh >> /vol51/apps/production/logs/gwl_prdctn.log 2>&1 &'`
echo "GWL PRODSTAT DATA LOAD HAS BEEN STARTED"
else echo "GWL PRODSTAT DATA LOAD IS ALREADY RUNNING"
fi
echo "next"
if [ `grep ASI_gwl_accusort_prdctn. "${killfile}" | wc -l ` -eq 0 ]
then `su - gwlop -c 'nohup /vol51/gwlop/data_conversion/ASI_gwl_accusort_prdctn.sh >> /vol51/apps/production/logs/ASI_prdctn.log 2>&1 &'`
echo "GWL ASI PROD DATA LOAD HAS BEEN STARTED"
else echo "GWL ASI PROD DATA LOAD IS ALREADY RUNNING"
fi


rm $killfile

exit 0
Take time to smell the roses.
4 REPLIES 4
Ramkumar Devanathan
Honored Contributor
Solution

Re: nohup script hanging on second command

hi,

you su command shouldn't contain a ' - ' after the su call.

that logs in and creates a new shell for the particular user. as long as the shell runs, the next command will never be run.

just run the su commands as below -

su spkop -c 'nohup /vol51/spkop/data_conversion/archive_accusort_prdctn.sh >> /vol51/apps/production/logs/spk_prdctn.log 2>&1 &'`

However, if you want the users environment settings to come into effect, before the command is run, then the above command would fail.

HTH.

- ramd.
HPE Software Rocks!
Clara Rowe
Frequent Advisor

Re: nohup script hanging on second command

Excellent!!!! Thank you so much that worked like a charm.
Take time to smell the roses.
John Poff
Honored Contributor

Re: nohup script hanging on second command

Hi,

I'm not sure that you need the backticks around the su command line. You should be able to execute that command from your script without the backticks. Since you aren't using the output of the su command line, it should work fine.

Also, it looks like you are using the contents of the $killfile to see if each of the processes is running. Another way to do that might be like this:

if $(UNIX95=1 ps -fC archive_accusort_prdctn.sh >/dev/null);
then
nohup ....
echo "SPK HAS BEEN STARTED"
else
echo "SPK IS ALREADY RUNNING"
fi

Using the XPG4 part of ps [which is why the UNIX95=1 is used] makes it easier to look for a particular process.

JP
Ramkumar Devanathan
Honored Contributor

Re: nohup script hanging on second command

hi Clara,

I might have been wrong about the shell not exiting part.. that i'd mentioned in my reply.

the comand is run as specified user and then is logged out from.

http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x638038dfa974d711abdc0090277a778c,00.html

I learnt this today.. sorry for the misinformation.

- ramd.
HPE Software Rocks!