How to create a cronjob that runs every 5 minutes from 8:30 AM to 9:30 PM? - linux

I am trying to run a cron job every 5 minutes from 8:30 AM to 9:30 PM. I've been searching around the web and here is what I came up with:
30,35,40,45,50,55 8 * * * /path/to/whatever.sh >> /var/log/whatever.log 2>&1
*/5 9-21 * * * /path/to/whatever.sh >> /var/log/whatever.log 2>&1
5,10,15,20,25,30 22 * * * /path/to/whatever.sh >> /var/log/whatever.log 2>&1
I have looked at cron job generators but they do not seem to address the requirement to start/end on the half-hour. Does anyone have a better or more concise solution?

30-59/5 8 * * * /path/to/whatever.sh >> /var/log/whatever.log 2>&1
*/5 9-20 * * * /path/to/whatever.sh >> /var/log/whatever.log 2>&1
0-30/5 21 * * * /path/to/whatever.sh >> /var/log/whatever.log 2>&1
should also work, and easier to read.

30-59/5 8-20 * * * /path/to/whatever.sh >> /var/log/whatever.log 2>&1
00-25/5 9-21 * * * /path/to/whatever.sh >> /var/log/whatever.log 2>&1
would serve the purpose.

Related

Crontab can only schedule for every minutes

So i want to try make a basic schedule with crontab, this is the basic script :
* * * * * date >> /home/clauds/crontab.log
* * * * * cp /home/clauds/ahmadbagas /home/clauds/bckup
* * * * * cp /home/clauds/masjayeng.txt /home/clauds/bckup
if i do it like that it works, but when i try to change to backup file for every 5 minutes or else it doesn't work:
5 * * * * date >> /home/clauds/crontab.log
2 * * * * cp /home/clauds/ahmadbagas /home/clauds/bckup
5 * * * * cp /home/clauds/masjayeng.txt /home/clauds/bckup
i try to add user in the command like this :
5 * * * * root date >> /home/clauds/crontab.log
2 * * * * root cp /home/clauds/ahmadbagas /home/clauds/bckup
5 * * * * root cp /home/clauds/masjayeng.txt /home/clauds/bckup
it's still doesn't work, and give a error message like this:
/bin/sh: root: command not found
can someone help me, why am i only can make schedule for everyminutes?
*/5 * * * * date >> /home/clauds/crontab.log
*/2 * * * * cp /home/clauds/ahmadbagas /home/clauds/bckup
*/5 * * * * cp /home/clauds/masjayeng.txt /home/clauds/bckup
The second one will be every two minutes

Linux Cronjob does not execute

I created a cronjob with the command crontab -e:
* * * * * (filename).sh
This file test.sh should be executed every minute. But it doesn't work.
I know that it is not the script because i did run bash (name of the file) it works so the crontad is the issue.
every minute:
* * * * * sciptname.sh
every 24hours (every midnight):
0 0 * * * sciptname.sh

Crontab every other hour and then the other hours

I have crontab scripts that run every other hour
2 */2 * * * cd /home/myuser/scripts && ./script.sh
4 */2 * * * cd /home/myuser/scripts && ./script2.sh
6 */2 * * * cd /home/myuser/scripts && ./script3.sh
8 */2 * * * cd /home/myuser/scripts && ./script4.sh
...
I would like to add more scripts that run on every other hour, but not the hours that the above scripts run on. So that the above scripts all run on their respective hour/minutes lets say on 1PM, 3PM ... and my new scripts run on 2PM, 4PM ...
I think you mean you want the new scripts to run on every other odd hour. If that's the case:
2 1-23/2 * * * cd /home/myuser/scripts && ./script5.sh
4 1-23/2 * * * cd /home/myuser/scripts && ./script6.sh
6 1-23/2 * * * cd /home/myuser/scripts && ./script7.sh
8 1-23/2 * * * cd /home/myuser/scripts && ./script8.sh
...
So script5.sh will run exactly one hour before/after script.sh, and script6.sh will run exactly one hour before/after script2.sh.
A reference: http://www.poweradded.net/2011/04/how-to-run-cron-jobs-on-evenodd-days.html
And if I'm interpreting your question correctly, I think it's been asked before: Specifying "all odd values" in crontab?

My VPS restarting every hour

Hello my server is restarting every hour, where the problem ?
Centos 6.6 with WHM/Cpanel
This my cronjob
root#server [/etc/cron.d]# crontab -l
0 6 * * * /usr/local/cpanel/scripts/exim_tidydb > /dev/null 2>&1
30 5 * * * /usr/local/cpanel/scripts/optimize_eximstats > /dev/null 2>&1
2,58 * * * * /usr/local/bandmin/bandmin
0 0 * * * /usr/local/bandmin/ipaddrmap
18 23 * * * /usr/local/cpanel/scripts/upcp --cron
0 1 * * * /usr/local/cpanel/scripts/cpbackup
0 2 * * * /usr/local/cpanel/bin/backup
35 * * * * /usr/bin/test -x /usr/local/cpanel/bin/tail-check && /usr/local/cpanel/bin/tail-check
45 */4 * * * /usr/bin/test -x /usr/local/cpanel/scripts/update_mailman_cache && /usr/local/cpanel/scripts/update_mailman_cache
30 */4 * * * /usr/bin/test -x /usr/local/cpanel/scripts/update_db_cache && /usr/local/cpanel/scripts/update_db_cache
30 */2 * * * /usr/local/cpanel/bin/mysqluserstore >/dev/null 2>&1
15 */2 * * * /usr/local/cpanel/bin/dbindex >/dev/null 2>&1
15 */6 * * * /usr/local/cpanel/scripts/autorepair recoverymgmt >/dev/null 2>&1
*/5 * * * * /usr/local/cpanel/bin/dcpumon >/dev/null 2>&1
46 0 * * * /usr/local/cpanel/whostmgr/docroot/cgi/cpaddons_report.pl --notify
7,22,37,52 * * * * /usr/local/cpanel/whostmgr/bin/dnsqueue > /dev/null 2>&1
42 4 * * * /usr/local/cpanel/3rdparty/bin/freshclam --quiet --no-warnings
Just looking at your cron jobs I can see that this job runs every hour, so that is a good place to start looking:
35 * * * * /usr/bin/test -x /usr/local/cpanel/bin/tail-check && /usr/local/cpanel/bin/tail-check
Also, this job runs twice an hour, but they happen so close together that it might appear to occur only once. Check it out next:
2,58 * * * * /usr/local/bandmin/bandmin
If you can, I would just comment out these 2 jobs for a few hours and see if that solves your problem. If it does then you know one of these is causing the reboot.

multiple crontab jobs but only one of them should not send email

I know that crontab job emails output of the job to its user. In my crontab file I have multiple jobs like:
10 21 * * * test1.sh
13 21 * * * test2.sh
0 * * * * test3.sh
I don't want to receive email for test3.sh. Does below code works? I want to make sure that only for the last job I wont receive email.
10 21 * * * test1.sh
13 21 * * * test2.sh
MAILTO=""
0 * * * * test3.sh
See http://www.cyberciti.biz/faq/disable-the-mail-alert-by-crontab-command/
You could use something like
0 * * * * test3.sh >/dev/null 2>&1
There will be no output --> no mail sent.

Resources