nohup in cron job


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting nohup in cron job
# 1  
Old 11-21-2005
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
# 2  
Old 11-21-2005
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
This User Gave Thanks to mschwage For This Post:
# 3  
Old 11-22-2005
Hi thr,
try to put ". .profile" at the start of your calling script.

I guess "&" does not work in cron.

Regards
Abhijeet
# 4  
Old 11-22-2005
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
# 5  
Old 11-22-2005
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
# 6  
Old 11-24-2005
MySQL

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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cron job - Need to run Cron every quarter at particular time

Hi, 1) If some job supposed to run on 1st of every month at 7 AM In cron job when we have a blackout on the 1st ( i.e when 1st falls on a sunday ) how can we make the job run the next business day? 2) How can we run a job on 25th of every quarter 7 AM(jan,apr,jul,oct) And if 25th... (5 Replies)
Discussion started by: System Admin 77
5 Replies

2. Shell Programming and Scripting

Commented cron job -- cron monitoring

Hi I have a requirement to write a shell script,that will check the all commented job in cron job.Please help !! (2 Replies)
Discussion started by: netdbaind
2 Replies

3. Solaris

Cron job running even after cron is removed

Hi , I have removed a cron for particular user , but cron job seems to be running even after the cron entry is removed. The purpose of the cron was to sendmail to user ( it uses mailx utility ) I have restarted cron and sendmail service still user is getting mail alerts from the cron job. And... (4 Replies)
Discussion started by: chidori
4 Replies

4. UNIX for Dummies Questions & Answers

nohup - sub job in script not executing until I exit

My job is launched using this command: I'm at home and having VPN drops so I used nohup and background. nohup perf_mon -c rating_4_multi,cfg & The main script is PID 26119, and the sub task under it is 26118 which is not running - just sits there. 26119 runs forever but nothing else runs. I... (2 Replies)
Discussion started by: ido1957
2 Replies

5. AIX

Backgroup job using nohup

Hi, I ran a program like following sample.sh & Later I realized that this job will take more hours to complete. Since it consumed 2 hours dat aprocessing and I don't want to terminate and then start the job like nohup sample.sh & Can you please tell me, is it possible to make this job no... (5 Replies)
Discussion started by: shahnazurs
5 Replies

6. UNIX for Dummies Questions & Answers

can't cancel nohup job

Yesterday I started a nohup job called assoc.sh. It has not finished running, but I have realised a problem with my script, so wish to cancel it, modify and restart it. However, I cannot find the PID, so can't cancel it. I have searched the ps list and nothing resembles my job - how can I cancel... (13 Replies)
Discussion started by: polly_falconer
13 Replies

7. Solaris

nohup in cron erntry

Hi , can one makes nohup inside the crontab entry? Inside a perl script also ? Regards Megh (2 Replies)
Discussion started by: megh
2 Replies

8. Shell Programming and Scripting

stoped job using ctrl+z now want to run in nohup

once i have stoped process by ctrl+z then i want to run it again in nohup plz help me out. (6 Replies)
Discussion started by: RahulJoshi
6 Replies

9. Solaris

cron job starts new cron proccess

I run cron in solaris 10 zone. One cron job which syncing files to nfs mounted on container, creates after finishing another cron proccess(/usr/sbin/cron), and after 100 existing cron proccesses next cron job will not start. It's too weird for me, I'm not able to solve this problem. Theoretically... (3 Replies)
Discussion started by: ron76
3 Replies

10. Shell Programming and Scripting

nohup in cron

Hello Gurus, I have written two simple shell scripts which i want to run daily via cronjob. One of the scripts contains "nohup" ,which is not getting executed when i run via cron. Why does "nohup" is not working via cron? Both the scripts work well when i run them manually.I have tested... (6 Replies)
Discussion started by: abhijeetkul
6 Replies
Login or Register to Ask a Question