LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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-14-2012, 08:25 PM   #1
BannerSchafer
LQ Newbie
 
Registered: Jul 2012
Posts: 1

Rep: Reputation: Disabled
Opening a script with crontab


Hi-

I am having some trouble with crontab. I have a file called backup.sh in bin and I want to execute that every day of the week. I tried adding the following line to my crontab file in etc.

30 3 * * * root /bin/backup.sh

I know that backup.sh works because I can sudo backup.sh from the terminal and it works. I than tried doing simpler things like:

* * 15 7 * root echo "Write this every minute to the terminal"

That didn't work either. Is there anything I am missing? Does anyone know what's happening?

Thanks.
 
Old 07-14-2012, 09:42 PM   #2
Toggan
Member
 
Registered: Oct 2011
Distribution: CentOS 5.9
Posts: 39

Rep: Reputation: 6
Instead of adding it to /etc/crontab, do you experience the same problem when you modify the root user's crontab by running 'sudo crontab -e'?
 
Old 07-14-2012, 10:01 PM   #3
tonyfreeman
Member
 
Registered: Sep 2003
Location: Fort worth, TX
Distribution: Debian testing 64bit at home, EL5 32/64bit at work.
Posts: 196

Rep: Reputation: 30
Quote:
Originally Posted by BannerSchafer View Post
30 3 * * * root /bin/backup.sh
The above crontab syntax is used for "system" cron jobs that can be found in files located in this directory: /etc/cron.d/

To make the backup work in root's user crontab (not system crontab) the above would need to be changed to look like this:

Code:
30 3 * * * /bin/backup.sh
Notice that 'root' is not specified? That's because you put it in root's user crontab (by typing "crontab -e" and entering the line) so ... naturally ... root will be the user running the /bin/backup.sh script.

All user and root specific cron jobs can be found somewhere in here: /var/spool/cron/ (or thereabouts depending on your distribution).

So if you have a user named tony then his cron jobs would be in a file called /var/spool/cron/tony The 'tony' user can edit his own cron by typing 'crontab -e' ... when he saves it it will go to /var/spool/cron/tony

If there is a system controlled crontab it will be here: /etc/cron.d/ ... and a username needs to be specified here in order to tell cron who to run the line as.

There are also system directories for scripts to be stored and executed by cron as the root user. Your backup.sh script could be moved to: /etc/cron.daily/ ... and it will be executed every day by cron as the root user.

Hope this helps.

Last edited by tonyfreeman; 07-14-2012 at 10:04 PM. Reason: more info
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Script crontab jedi777 Linux - Newbie 2 01-27-2011 12:52 AM
[SOLVED] Crontab Script Not Running th1bill Ubuntu 4 12-10-2010 03:49 PM
[SOLVED] one script does not work at crontab windstory Linux - Newbie 7 08-13-2010 02:56 AM
Runs Multiple shell script inside a main script using crontab srimal Linux - Newbie 4 10-22-2009 06:19 PM
crontab not finding script michaeln *BSD 4 08-22-2004 10:07 PM

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

All times are GMT -5. The time now is 02:53 PM.

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