LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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 07-16-2010, 05:10 AM   #1
deelinux
Member
 
Registered: Nov 2009
Posts: 39

Rep: Reputation: 15
crontab


Hello

I have set up my crontab and whilst Im logged in and it works (It runs my shell script), however when Im not logged in, the script does not run.

Initially I set the time/date to 0 0 * * * (Midnight every day), as this did not work, I tested it with to 0 * * * * (every hour) whilst logged in and the script starts.

I use crontab -e to set it up under the root account..

Im sure you dont have to be logged in for it to run?, but maybe im missing a step or just overdosing on Linux and need a holiday:-)

any suggestions would be great

Dee
 
Old 07-16-2010, 06:34 AM   #2
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,529

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
Which crontab are you running?
Any errors in the logfiles?
 
Old 07-16-2010, 06:34 AM   #3
rajivdp
Member
 
Registered: Oct 2008
Posts: 34

Rep: Reputation: 17
Hi Dee

You should source your ~/.bashrc or ~/.bash_profile file first in which the PATH environmental variable will get set for the binary PATHs.

By default the crontab will look for the binary in /usr/bin:/bin and if your script calls the binary that are in differen path(type #echo $PATH) then it ends up and cant finish off the job.

if you are executing bash script with the crontab you can add the following in the top of the script

. ~/.bashrc
. ~/.bash_profile

if you are executing some other script like perl or some other scripts, then you need to have a bash script in the crontab which sources the profile and RC file and then execute the perl or other script

Example:
#vi bash_script.sh
. ~/.bashrc
. ~/.bash_profile
perl otherscript.pl or someinterpreter otherscript

Regards
Rajiv
 
Old 07-16-2010, 07:50 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by deelinux View Post
I have set up my crontab and whilst Im logged in and it works (It runs my shell script), however when Im not logged in, the script does not run.
The script runs, but maybe it doesn't work as expected since it lacks something which is set upon login. Maybe does it requires an active DISPLAY?

As previously suggested check the logs to find out, e.g. /var/log/cron or /var/log/messages. Also check the root's mailbox using the mail command, since standard output and standard error (not redirected to a file) are sent there by the cron daemon (specifically to the crontab owner's mailbox).
 
  


Reply



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
linux crontab vs unix crontab ytd Linux - General 2 08-09-2009 05:07 AM
replaced crontab, now should get crontab back to what it was raminn Linux - Newbie 2 10-20-2008 07:15 PM
man crontab(5) vs crontab(1) Canis Polaris Linux - Newbie 2 06-04-2008 04:03 PM
no crontab? MrSako Linux - Software 17 12-22-2006 10:33 AM
system-wide crontab in /etc/crontab ner Linux - General 2 11-18-2003 12:35 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:29 AM.

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
Open Source Consulting | Domain Registration