LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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 09-16-2008, 09:54 AM   #1
xmdms
Member
 
Registered: Oct 2003
Posts: 134

Rep: Reputation: 15
Question Crontab entry question??


Greetings,

I am in the process to setup an entry in the crontab to run once every Sundat at 2:00 AM - I would like to know what's the crontab entry syntax look like.

I do know that the Crontab entry format, but not sure what to do for the Month or Day-of-Week tab.
(Min Hour Day Month Day-of-Week format)

Thanks,

J
 
Old 09-16-2008, 09:59 AM   #2
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
Just put * for month. Day of week should be 7. Do this command in a terminal for full details:
Code:
man 5 crontab
 
Old 09-16-2008, 09:59 AM   #3
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Debian, OS X
Posts: 1,298

Rep: Reputation: 102Reputation: 102
Smile This will certainly help you out, this is from my notes.

http://www.adminschoice.com/docs/crontab.htm
----------------------
CRONTAB (6 fields)
----------------------

FILES:

LINUX

1) /etc/cron.allow
2) /etc/cron.deny


Fields:-

Minute 0-59
Hour 0-23
Date 1-31
Month 1-12 (or names)
Day of Week 0-6 (or names) [ 0 is for Sunday ]




EXAMPLES

Example 1: Cleaning up core files

This example cleans up core files every weekday morning at
3:15 am:

Code:
15 3 * * 1-5 find $HOME -name core 2>/dev/null | xargs rm -f


Example 2: Mailing a birthday greeting

Code:
0 12 14 2 * mailx john%Happy Birthday!%Time for lunch.
Code:
0 12 14 2 * mailx john%Happy Birthday!%Time for lunch. > /dev/tty1
[ displays terminal 1 ]




Example 3: Specifying days of the month and week

This example

Code:
0 0 1,15 * 1
would run a command on the first and fifteenth of each
month, as well as on every Monday.

To specify days by only one field, the other field should be
set to *. For example:

Code:
 0 0 * * 1
would run a command only on Mondays.






crontab -e username Edit your crontab file, or create one if it doesn't already exist.
crontab -l username Display your crontab file.
crontab -r username Remove your crontab file.






CRONTAB Restrictions
________________________

You can execute crontab if your name appears in the file /usr/lib/cron/cron.allow. If that file does not exist, you can use crontab if your name does not appear in the file /usr/lib/cron/cron.deny.

If only cron.deny exists and is empty, all users can use crontab. If neither file exists, ONLY the root user can use crontab. The allow/deny files consist of one user name per line
 
Old 09-16-2008, 10:50 AM   #4
xmdms
Member
 
Registered: Oct 2003
Posts: 134

Original Poster
Rep: Reputation: 15
So, the syntax should be looking like this;
00 04 * * 0 /usr/my_file > /tmp/my_log.log 2>&1

The syntax above should execute every Sunday at 4:00 AM and log it in my log file, correct?

Thanks for your help!!

J
 
Old 09-17-2008, 05:04 AM   #5
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Debian, OS X
Posts: 1,298

Rep: Reputation: 102Reputation: 102
Wink yes

Quote:
Originally Posted by xmdms View Post
So, the syntax should be looking like this;
00 04 * * 0 /usr/my_file > /tmp/my_log.log 2>&1

The syntax above should execute every Sunday at 4:00 AM and log it in my log file, correct?

Thanks for your help!!

J
yes this is correct !!
 
Old 09-17-2008, 07:35 AM   #6
xmdms
Member
 
Registered: Oct 2003
Posts: 134

Original Poster
Rep: Reputation: 15
Thumbs up

Thank you!!

You guys are the best!!

J
 
  


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
Somehow not getting crontab entry right Jykke Linux - Desktop 4 02-29-2008 02:50 PM
Crontab entry doubt paventhan Solaris / OpenSolaris 1 11-03-2007 06:33 AM
crontab entry? Master Fox Linux - Software 4 08-23-2005 02:20 PM
crontab job entry notolerance Linux - Software 2 02-20-2005 03:40 PM
crontab entry pilipk01 Linux - General 4 11-19-2003 08:53 PM


All times are GMT -5. The time now is 01:17 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration