The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
nohup.out ramky79 AIX 5 10-23-2007 03:28 AM
nohup - help! bluemoon1 UNIX for Dummies Questions & Answers 9 10-11-2007 08:49 PM
Help on nohup bobbyjohnz UNIX for Advanced & Expert Users 3 10-18-2006 08:56 AM
Nohup miwinter UNIX for Dummies Questions & Answers 3 07-21-2006 02:20 AM
nohup in cron abhijeetkul Shell Programming and Scripting 6 11-19-2005 10:50 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 11-21-2005
Registered User
 

Join Date: Nov 2005
Posts: 3
nohup in cron job

Hello,
I have bunch of shell scripts, which I want to execute every hour in the background. So I created a script mainscript.sh which executes these hourly scripts in the background. Script goes like this.
mainscript.sh

#!/bin/sh
nohup sh subscript1.sh &
nohup sh subscrip2.sh &
exit 0


And I set up this mainscript.sh script through cron to execute every hour. When I run this script manually it runs all other scripts properly in the background. But nothing is happening with cron setup.

Your help is appreciable

thanks
papachi_2000
Reply With Quote
Forum Sponsor
  #2  
Old 11-21-2005
Registered User
 

Join Date: Jul 2005
Location: Oak Park, IL
Posts: 100
What does your cron entry look like?

Why are you using nohup? Nohup is for if you are logged in, and don't want the job to exit when you log out, if you start the job from a terminal.

Cron has no terminal associated with it. Therefore, nohup does not help you.
-Mike
Reply With Quote
  #3  
Old 11-22-2005
Registered User
 

Join Date: Oct 2005
Location: Mumbai,India
Posts: 58
Hi thr,
try to put ". .profile" at the start of your calling script.

I guess "&" does not work in cron.

Regards
Abhijeet
Reply With Quote
  #4  
Old 11-22-2005
Registered User
 

Join Date: Nov 2005
Posts: 3
I used nohup because like mike mentioned I don't want the job to exit when I log out. If Cron has no terminal associated with it, So that means I don’t have to use nohup?
But I want all shell scripts to execute background. If I don’t use '&' would they run in back ground? I don’t want them to wait for other shell to execute. So to achieve my requirement what should I do? And abhijeet I did used '. .profile' still it won’t work.

Thanks to all,
Papachi
Reply With Quote
  #5  
Old 11-22-2005
Registered User
 

Join Date: Sep 2005
Posts: 45
You don't need the nohup, because the script is running without being linked to a terminal session and nohup is needed when you want to end a session and keep a job running.

I could be wrong, but I think you're right to use the Ampersand to allow both subscripts to run concurrently.


I think the point Abhijeetkul was making about the .profile was that the environment used by the Cron job (root's?) will be different from your own and it may be that the PATH variable is not the same, so the job as run by the cron may not be able to find your script, or subscripts. You could try logging in as root (or whatever user's cron you're using) and running the script using the same command as entered in the cron to see if it works.

cheers
Reply With Quote
  #6  
Old 11-24-2005
Registered User
 

Join Date: Oct 2005
Location: Mumbai,India
Posts: 58
Thumbs up

Hello all,
I faced a similar problem recently.Only exception was i need not have "&".
All my scripts were working fine when run manually,but not the same in cron.

I thought of calling my user's .profile in it & i succeeded.

Hope your problem solves out soon.

Try . $HOME/.profile


Regards
Abhijeet
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 06:15 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0