LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 12-28-2014, 02:43 PM   #1
tamtam
Member
 
Registered: May 2004
Distribution: Slackware.
Posts: 323

Rep: Reputation: 33
Strange cron job time setting


Someone has added a cron job to a server we maintain. We are aware of what the job entails, it is just the time settings the job is set to run we do not understand...

0-59/15 * * * 1-5 cd /home/tthome/services/; perl bin/update_count.pl

When does the above run? Every minute or fifteen minutes?

The reason I am asking. The job is system intensive and results in a high system load.

Your input welcome.
 
Old 12-28-2014, 04:14 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,409
Blog Entries: 55

Rep: Reputation: 3582Reputation: 3582Reputation: 3582Reputation: 3582Reputation: 3582Reputation: 3582Reputation: 3582Reputation: 3582Reputation: 3582Reputation: 3582Reputation: 3582
Quote:
Originally Posted by tamtam View Post
(..) it is just the time settings the job is set to run we do not understand (..) When does the above run? Every minute or fifteen minutes?
If you don't understand the time spec then please read 'man 5 crontab'. And BTW you could test this yourself, substituting something innocuous (like a plain 'echo') for the actual command. It suffices to say the time spec of this cron job has no relation to the load it generates.
 
Old 12-28-2014, 04:25 PM   #3
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,258

Rep: Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914
if this is the logic that cron follows then my guess is it will execute on 0,1,2,3 minutes past each hour on mon thru fri (not sure if that is what is intended):
Code:
[liveuser@localhost ~]$ i=0; while [ $i -le 59 ]
> do
>  echo expr $i / 15 = `expr $i / 15`
>  i=`expr $i + 1`
> done
expr 0 / 15 = 0
expr 1 / 15 = 0
expr 2 / 15 = 0
expr 3 / 15 = 0
expr 4 / 15 = 0
expr 5 / 15 = 0
expr 6 / 15 = 0
expr 7 / 15 = 0
expr 8 / 15 = 0
expr 9 / 15 = 0
expr 10 / 15 = 0
expr 11 / 15 = 0
expr 12 / 15 = 0
expr 13 / 15 = 0
expr 14 / 15 = 0
expr 15 / 15 = 1
expr 16 / 15 = 1
expr 17 / 15 = 1
expr 18 / 15 = 1
expr 19 / 15 = 1
expr 20 / 15 = 1
expr 21 / 15 = 1
expr 22 / 15 = 1
expr 23 / 15 = 1
expr 24 / 15 = 1
expr 25 / 15 = 1
expr 26 / 15 = 1
expr 27 / 15 = 1
expr 28 / 15 = 1
expr 29 / 15 = 1
expr 30 / 15 = 2
expr 31 / 15 = 2
expr 32 / 15 = 2
expr 33 / 15 = 2
expr 34 / 15 = 2
expr 35 / 15 = 2
expr 36 / 15 = 2
expr 37 / 15 = 2
expr 38 / 15 = 2
expr 39 / 15 = 2
expr 40 / 15 = 2
expr 41 / 15 = 2
expr 42 / 15 = 2
expr 43 / 15 = 2
expr 44 / 15 = 2
expr 45 / 15 = 3
expr 46 / 15 = 3
expr 47 / 15 = 3
expr 48 / 15 = 3
expr 49 / 15 = 3
expr 50 / 15 = 3
expr 51 / 15 = 3
expr 52 / 15 = 3
expr 53 / 15 = 3
expr 54 / 15 = 3
expr 55 / 15 = 3
expr 56 / 15 = 3
expr 57 / 15 = 3
expr 58 / 15 = 3
expr 59 / 15 = 3

Last edited by schneidz; 12-28-2014 at 04:27 PM.
 
Old 12-28-2014, 04:46 PM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,409
Blog Entries: 55

Rep: Reputation: 3582Reputation: 3582Reputation: 3582Reputation: 3582Reputation: 3582Reputation: 3582Reputation: 3582Reputation: 3582Reputation: 3582Reputation: 3582Reputation: 3582
Quote:
Originally Posted by schneidz View Post
my guess is it will execute on 0,1,2,3 minutes past each hour
A different way of writing the first field "0-59" part is "*". So you actually get "*/15".
 
1 members found this post helpful.
Old 12-28-2014, 05:49 PM   #5
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,258

Rep: Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914
http://linux.die.net/man/5/crontab :
Quote:
Step values can be used in conjunction with ranges. Following a range with "<number>" specifies skips of the number's value through the range. For example, "0-23/2" can be used in the hours field to specify command execution every other hour (the alternative in the V7 standard is "0,2,4,6,8,10,12,14,16,18,20,22"). Steps are also permitted after an asterisk, so if you want to say "every two hours", just use "*/2".
 
Old 12-29-2014, 03:27 PM   #6
tamtam
Member
 
Registered: May 2004
Distribution: Slackware.
Posts: 323

Original Poster
Rep: Reputation: 33
Okay, thanks for suggestions guys. cron job run once every fifteen minutes. We normally use */5 for like every five minutes etc.

To test created a simple perl script and set it to run...
Quote:
bash-4.2$ cat cron-test.pl
#!/usr/bin/perl
#
#
# Tester for cron time settings
#

my $time = localtime();

print "Script is running at $time\n";
modified cron with crontab -e

Quote:
bash-4.2$ crontab -l
# Cron job for testing time settings

0-59/15 * * * 1-5 cd /home/tam/work/perl/; perl cron-test.pl >> /home/tam/work/perl/output.log
output

Quote:
bash-4.2$ cat output.log
Script is running at Mon Dec 29 16:30:01 2014
Script is running at Mon Dec 29 16:45:01 2014
Script is running at Mon Dec 29 17:00:01 2014
Script is running at Mon Dec 29 17:15:01 2014
Script is running at Mon Dec 29 17:30:01 2014
Script is running at Mon Dec 29 17:45:01 2014
Script is running at Mon Dec 29 18:00:01 2014
Script is running at Mon Dec 29 18:15:01 2014
Script is running at Mon Dec 29 18:30:01 2014
Script is running at Mon Dec 29 18:45:01 2014
Script is running at Mon Dec 29 19:00:01 2014
 
  


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
Strange cron job issue smilemukul Linux - Newbie 1 10-02-2012 06:27 AM
Cron Job: Start it Only once on specified time jCash Linux - Newbie 2 12-07-2007 07:35 PM
cron job - strange behaviour macadam Linux - Software 3 07-20-2006 11:45 PM
problem in cron job setting gauravdream Linux - General 1 02-23-2004 12:08 AM
need help setting up a cron job !! J.I.L. Linux - Software 1 10-19-2003 08:54 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

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