Script dosent exits after executing the script | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Script dosent exits after executing the script

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 04-18-2013
vikatakavi vikatakavi is offline
Registered User
 
Join Date: Feb 2013
Last Activity: 14 October 2014, 9:57 AM EDT
Posts: 50
Thanks: 25
Thanked 1 Time in 1 Post
Bug Script dosent exits after executing the script

Hi i wrote a script which dosent exists after executing any help


Code:
#!/bin/bash
netstat -ptlen | grep 10000
if [ $? -eq 0 ] ; then
  echo "Hive Thrift server is running"
 exit 0
 else
  echo "Hive Thrift server is down Trying to Bring up the service" | mail -s "ALERT" team@domain.com 
`nohup hive --service hiveserver &`
echo "Restarted the service"
fi

Sponsored Links
    #2  
Old 04-18-2013
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 25 October 2014, 1:15 PM EDT
Location: Saskatchewan
Posts: 19,685
Thanks: 824
Thanked 3,352 Times in 3,139 Posts
There is no point using backticks ` ` there, at best they do nothing and at worst they can cause a syntax error if the command prints anything.

Your shell may be waiting for the launched process to quit, some do, but you can tell them to not wait with disown.

Code:
if netstat -ptlen | grep 10000
then
        echo "Hive Thrift server is running"
else
        echo "Hive Thrift server is down Trying to Bring up the service" | mail -s "ALERT" team@domain.com

        nohup hive --service hiveserver &
        disown
fi

Sponsored Links
    #3  
Old 04-18-2013
vikatakavi vikatakavi is offline
Registered User
 
Join Date: Feb 2013
Last Activity: 14 October 2014, 9:57 AM EDT
Posts: 50
Thanks: 25
Thanked 1 Time in 1 Post
HI Corona688 thansk for the quick reply.

i made changes as above ,but still i had to do CTRL+C to return normal screeen
    #4  
Old 04-18-2013
hanson44 hanson44 is offline
Registered User
 
Join Date: Mar 2013
Last Activity: 12 May 2013, 11:33 PM EDT
Posts: 858
Thanks: 18
Thanked 180 Times in 177 Posts
Do you have to do CTL-C or does just ENTER also return you to normal screen? nohup always writes some text to the monitor. So maybe you just don't see the command prompt displayed?
Sponsored Links
    #5  
Old 04-18-2013
vikatakavi vikatakavi is offline
Registered User
 
Join Date: Feb 2013
Last Activity: 14 October 2014, 9:57 AM EDT
Posts: 50
Thanks: 25
Thanked 1 Time in 1 Post
Enter also works to exit,it writes on to my home to file nohup.out. But how if i want it run using a cron job ,i cant do enter at that time

Last edited by vikatakavi; 04-18-2013 at 04:55 PM..
Sponsored Links
    #6  
Old 04-18-2013
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 25 October 2014, 1:15 PM EDT
Location: Saskatchewan
Posts: 19,685
Thanks: 824
Thanked 3,352 Times in 3,139 Posts
Quote:
Originally Posted by vikatakavi View Post
Enter also works to exit,i writes on to my home to file nohup.out
Your program has already quit when you see that message -- it just looks odd, because nohup has printed junk overtop of your prompt right after.

Normally this doesn't happen because the shell waits for the program to quit before printing a prompt. But you have specifically told the shell not to wait.
The Following User Says Thank You to Corona688 For This Useful Post:
vikatakavi (04-18-2013)
Sponsored Links
    #7  
Old 04-18-2013
hanson44 hanson44 is offline
Registered User
 
Join Date: Mar 2013
Last Activity: 12 May 2013, 11:33 PM EDT
Posts: 858
Thanks: 18
Thanked 180 Times in 177 Posts
Quote:
But how if i want it run using a cron job
Just get rid of the nohup, and do not put in background. It will run fine in crontab, unless some other factor. If output is produced, redirect it to /dev/null or a file.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Shell scripts exits after executing ypmatch manju-- Shell Programming and Scripting 1 09-06-2011 04:40 PM
'script' command exits immediately jalburger Shell Programming and Scripting 6 04-19-2011 08:24 AM
Exits from putty instead of shell script Imran_Chennai Shell Programming and Scripting 14 02-21-2011 02:20 AM
Exit script if the user dosent enter any data within 5 seconds frozensmilz Shell Programming and Scripting 3 03-18-2009 03:30 AM
Script exits with $? not 0 randomly, how can I see what command failed? trailsmoke Shell Programming and Scripting 2 09-25-2008 10:52 AM



All times are GMT -4. The time now is 05:09 PM.