LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   Strange cron job time setting (https://www.linuxquestions.org/questions/linux-server-73/strange-cron-job-time-setting-4175529414/)

tamtam 12-28-2014 02:43 PM

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.

unSpawn 12-28-2014 04:14 PM

Quote:

Originally Posted by tamtam (Post 5291638)
(..) 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.

schneidz 12-28-2014 04:25 PM

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


unSpawn 12-28-2014 04:46 PM

Quote:

Originally Posted by schneidz (Post 5291692)
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".

schneidz 12-28-2014 05:49 PM

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".

tamtam 12-29-2014 03:27 PM

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


All times are GMT -5. The time now is 05:37 PM.