LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-21-2013, 04:34 AM   #1
nishanth_rddy
LQ Newbie
 
Registered: Sep 2013
Posts: 8

Rep: Reputation: Disabled
Nohup command in Shell script


Hi

i have a below sample Shell script.

bash-3.2$ cat 1.sh
#
#
a=`ps ucx|grep -i ABC|wc -l`
if [ $a = 0 ]
then
nohup sh startprocess.sh &
echo "started process "
else
echo "process runing fine "
#
fi
bash-3.2$


this has to be setup as a crontab. if i run that script it will hang at nohup. do we have anything to Comeout of nohup.
 
Old 09-21-2013, 05:06 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
The script doesn't hang, but waits for a carriage return. This is caused by the sh part, try this instead:
Code:
nohup /full/path/to/startprocess.sh &
 
Old 09-21-2013, 05:19 AM   #3
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530
...additionally you might mean:
Code:
COUNT=`pgrep -f ABC|wc -l`
or if you have BASH:
Code:
COUNT=($(pgrep -f ABC)); [ ${#COUNT[@]} -eq 0 ] && doSomething
where doSomething() can be defined as what druuna wrote or as
Code:
doSomething() { echo "/path/to/nohup /path/to/startprocess.sh"|/path/to/at now; }
if you have access to the (underrated and rarely mentioned) 'at' service.
 
Old 09-21-2013, 09:53 AM   #4
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,604

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
Actually, it hangs because stdout/stderr/stdin is still sent to the cron job log...

I would suggest redirecting them...

nohup sh startprocess.sh </dev/null >$HOME/logfile 2>&1 &

If "startprocess.sh" is an executable shell script then you can drop the "sh" command.
 
Old 09-21-2013, 10:18 AM   #5
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Assuming this is what you are talking about:
Code:
nohup sh startprocess.sh &
Quote:
Originally Posted by jpollard View Post
Actually, it hangs because stdout/stderr/stdin is still sent to the cron job log...
It also "hangs" (waits for CR) when ran from the command line.

Last edited by druuna; 09-21-2013 at 10:22 AM.
 
Old 09-22-2013, 10:36 AM   #6
nishanth_rddy
LQ Newbie
 
Registered: Sep 2013
Posts: 8

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by druuna View Post
The script doesn't hang, but waits for a carriage return. This is caused by the sh part, try this instead:
Code:
nohup /full/path/to/startprocess.sh &
Drunna even after using fullpath its hanging

bash-3.2$ ./2.sh
bash-3.2$ /usr/bin/nohup: appending output to `nohup.out'

bash-3.2$ cat 2.sh
#!/bin/bash
/usr/bin/nohup /u10/TEST/bin/startWeblogic.sh &
exit

Can you please help me ?

Last edited by nishanth_rddy; 09-22-2013 at 09:42 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell: Sending an email after nohup command exits vxc69 Programming 2 05-14-2013 12:00 PM
Passing parameters to script using nohup and invoked shell aedurkee Linux - Server 3 12-13-2012 08:49 AM
nohup command in script doesn't return to system console prompt beammeup Linux - Software 4 02-05-2007 03:01 PM
problem with nohup command and nohup file size vbseeker Linux - General 1 09-17-2006 12:36 PM
Shell script using nohup hangs lloracle_dba Programming 7 05-04-2005 11:52 AM


All times are GMT -5. The time now is 12:25 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration