LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 04-22-2011, 10:30 AM   #1
m4rtin
Member
 
Registered: Sep 2007
Posts: 261

Rep: Reputation: 16
"*\1" vs "*" in crontab file


I tried to set up the /etc/contab file under Debian. I would like to run one script every minute. At first I set a following line:

Code:
1 *	*	*	*	root  date > /tmp/date
..however, it looks like the cron is not creating a new /tmp/date file every minute. So I modified this line to look like this:

Code:
*\1	*	*	*	*	root  date > /tmp/date
..and now I get a new /tmp/date every minute. Why doesn't this 1 in minute field mean "after every 1 minute"?
 
Old 04-22-2011, 10:34 AM   #2
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
AFAIK, if you just specify the 1, the script will be run every first minute of the hour, like 00:01, 01:01, 02:01 , ..., 23:01.
It is not run every minute.
 
Old 04-22-2011, 11:37 AM   #3
SL00b
Member
 
Registered: Feb 2011
Location: LA, US
Distribution: SLES
Posts: 375

Rep: Reputation: 112Reputation: 112
Tobi is correct. If you specify 1, it'll run on the first minute of every hour. If you specify */1, it'll run every minute. You could have just specified * and achieved the same result, because cron checks its tables every minute to see if it has a job to run.

Likewise, if you specify 5, it'll run on the fifth minute, whereas */5 means every five minutes.
 
Old 04-22-2011, 11:38 AM   #4
m4rtin
Member
 
Registered: Sep 2007
Posts: 261

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by TobiSGD View Post
AFAIK, if you just specify the 1, the script will be run every first minute of the hour, like 00:01, 01:01, 02:01 , ..., 23:01.
It is not run every minute.
ok, I see. So to run for example something after every two hours, one should specify:

Code:
*	*/2	*	*	*	root  date > /tmp/date
..otherwise:

Code:
*	2	*	*	*	root  date > /tmp/date
..it would be 02:00 every day?
 
Old 04-22-2011, 11:39 AM   #5
SL00b
Member
 
Registered: Feb 2011
Location: LA, US
Distribution: SLES
Posts: 375

Rep: Reputation: 112Reputation: 112
Correct.
 
Old 04-22-2011, 12:34 PM   #6
m4rtin
Member
 
Registered: Sep 2007
Posts: 261

Original Poster
Rep: Reputation: 16
SL00b, TobiSGD: thanks!

One more thing regarding crontab- in Mark G. Sobell "Practical Guide to Linux Commands, Editors, and Shell Programming, A (2nd Edition)" on page 651 there is a following example:

Code:
00 02 * * 0,4 $HOME/bin/twice.week
..and the explanation is "twice.week runs at 12:02 AM on Sunday and Thursday (days 0 and 4)". Is this a mistake? This should be "twice.week runs at 02:00 AM on Sunday and Thursday (days 0 and 4)", shouldn't it?
 
Old 04-22-2011, 12:49 PM   #7
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
Quote:
Originally Posted by m4rtin View Post
SL00b, TobiSGD: thanks!

One more thing regarding crontab- in Mark G. Sobell "Practical Guide to Linux Commands, Editors, and Shell Programming, A (2nd Edition)" on page 651 there is a following example:

Code:
00 02 * * 0,4 $HOME/bin/twice.week
..and the explanation is "twice.week runs at 12:02 AM on Sunday and Thursday (days 0 and 4)". Is this a mistake? This should be "twice.week runs at 02:00 AM on Sunday and Thursday (days 0 and 4)", shouldn't it?
Yes, I would consider this a mistake in the book. In fact I have an entry like "0 2 * * *" in my root's crontab on the fileserver that syncs every night at 02:00 AM my Slackware mirror.
 
Old 04-22-2011, 12:54 PM   #8
SL00b
Member
 
Registered: Feb 2011
Location: LA, US
Distribution: SLES
Posts: 375

Rep: Reputation: 112Reputation: 112
Yeah... in fact, looking at the previous example, I think I may have answered incorrectly.

Code:
*	  2	*	*	*	root  date > /tmp/date
If I'm interpreting correctly, this would not run every day at 2:00. This would run every minute from 2:00 to 2:59.
 
Old 04-22-2011, 07:12 PM   #9
m4rtin
Member
 
Registered: Sep 2007
Posts: 261

Original Poster
Rep: Reputation: 16
TobiSGD, thanks! That's what I thought as well. I sent an email to Mark G. Sobell


Quote:
Originally Posted by SL00b View Post
Yeah... in fact, looking at the previous example, I think I may have answered incorrectly.

Code:
*	  2	*	*	*	root  date > /tmp/date
If I'm interpreting correctly, this would not run every day at 2:00. This would run every minute from 2:00 to 2:59.
I tested this out and this:

Code:
*	  2	*	*	*	root  date > /tmp/date
..indeed means "every minute from 2:00 to 2:59"
 
  


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
how can I "cat" or "grep" a file to ignore lines starting with "#" ??? callagga Linux - Newbie 7 08-16-2013 06:58 AM
"bad tty" & "file descriptor error" while building RPM on F13 gosssamer Linux - Software 7 12-28-2010 05:02 PM
net working eth0 eth1 wlan0 "no connection" "no LAN" "no wi-fi" Cayitano Linux - Newbie 5 12-09-2007 07:11 PM
Standard commands give "-bash: open: command not found" even in "su -" and "su root" mibo12 Linux - General 4 11-11-2007 10:18 PM
LXer: Displaying "MyComputer", "Trash", "Network Servers" Icons On A GNOME Desktop LXer Syndicated Linux News 0 04-02-2007 08:31 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:37 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