1751712 Members
5250 Online
108781 Solutions
New Discussion юеВ

crontab

 
xiandao
Occasional Advisor

crontab

Do anyone know if the crontab can only start a foreground job?
What I mean is that I have a shell script which has one foreground job and one background job.
It works well if I start it from the command line.
But the background job doesn't work if it is started by crontab.
Do anyone have any ideas?

Please reply me asap. Thanks.
5 REPLIES 5
Steve Steel
Honored Contributor

Re: crontab

Hi


Cron has another environment than the command line

You probably need to give full names for all commands and export all values

If it runs as a specific setup then add

. /home/user/.profile

To the script to run the profile in the same processing level


Steve Steel
If you want truly to understand something, try to change it. (Kurt Lewin)
Jose Mosquera
Honored Contributor

Re: crontab

Hi,

Pls do not forget *always* start your script with the desired shell, i.e:
#!/sbin/sh
your_procedure_line1
your_procedure_line2
etc...

Also do not forget uses the full path assignment for each command. To locate a full command path use:
#whence

Rgds.
Petr Simik_1
Valued Contributor

Re: crontab

there are only "background" jobs started in crontab there is no reason to put & after the command they all are started as "background". You have to specify full path to start processes.
You have to specify PATH. include .profile is the easiest way to do that.
And is good to specify output of scripts if it exists. Otherwise the output is directed to mail of user(owner).
Jan Sladky
Trusted Contributor

Re: crontab

hi,
in my opinion it is not needed to run jobs on background via cron.
Normally it is used only if you have only one tty and want to have access on the tty and run some jobs simultaneously.

I suggest only redirect STDOUT & STDERR into logfile

23 59 * * * /job.sh > /tmp/job.log 2>&1

hope tih will help you

br Jan
GSM, Intelligent Networks, UNIX
Michael Tully
Honored Contributor

Re: crontab

cron does not run foreground jobs, only jobs in the background. You'll have to provide part of your script for us to help.
Anyone for a Mutiny ?