Set a cron job to a specific timezone on Centos 7 - cron

I'm trying to set the cron jobs to run on a specific timezone, but I think I'm missing something.
I've tried to add TZ (And CRON_TZ) on top of the jobs in the /var/spool/cron/ file, but it doesn't seem to work.
TZ=Europe/Rome
* * * * * /usr/local/bin/php /home/user/folder/file.php
I've installed CWP7pro

from the manual:
Every * means something:
minute 0-59
hour 0-23
day of month 1-31
month 1-12 (or names, see below)
day of week 0-7 (0 or 7 is Sun, or use names)
if you want every minute use this
*/1
example:
*/15 * * 1 * means every 15 minutes on the 1st day of the month
Edit /etc/crontab or use
crontab -e (edit)
CRON_TZ should be used instead of TZ or use TZ inline
*/15 * * 1 * TZ=Europe/Rome echo "do something"

Related

Crontab error: "/tmp/crontab.calJpk":5: bad day-of-month

I am trying to run a crontab with the expression given below. But i am getting bad day-of-month error.
My requirement is to run this code:
everyday except Sunday
every hour starting 2 am till 10pm
0 2-22 ? * 0-6 * /usr/bin/python /my/location/to/python_code_for_cron/sampletest.py
Is there some issue with the cron expression or something else that i need to install?
FYI: I am using crontab -e to edit my crontab
You just have too many arguments in there. Read man -s5 crontab for more info. The fields are:
minute hour day-of-month month day-of-week
Also, 0-6 is the same as * for day-of-week. Your line should read:
0 2-22 * * 1-6 /usr/bin/python /my/location/to/python_code_for_cron/sampletest.py

Unsure what is wrong with cron tab

I am attempting to schedule a cron job for database backups using percona extra backup.
My cron job is in cron.d and looks as follows;
exec &>/var/tmp/cron.log
1 * * * * * secondstory_prod /var/opt/backup/percona_xtrabackup_incremental.sh > /var/tmp/cron.log
The error i receive when i try and force the jobs to run in the log file listed above is /etc/cron.d/db_backup_daily: line 2: 1: command not found
If i try to run the jobs forcefully with run-parts /etc/cron.d i get the above error.
What is strange is that if i navigate to the directory and run the percona_xtrabackup_incremental.sh file it works with no issues.
Please can someone help?
Thanks
Your problem is you have one too many * in your cron entry.
1 * * * * * secondstory_prod ..stuff..
should be
1 * * * * secondstory_prod ..stuff..
will run on every 1st minute of each hour every day (above). The general time entry format is:
* minute (0-59)
* hour (0-23)
* day of month (1-31)
* month (1-12)
* day of week (0-6) (0=Sunday)

cronjob which backs off during off-peak hours

I have a php script which crontab executes every 30 minutes, during off-peak hours around 2-7am I don't get much traffic and so I wish to not run the script during these hours.
I'm not sure how to make a cronjob that will do this as I would find it hard to test.
The cronjob I have at the moment looks like this
*/30 * * * * /usr/bin/php /var/www/update/inv.php
*/30 0-1,8-23 * * * /usr/bin/php /var/www/update/inv.php
the range is inclusive, so 0-1 will do 00:30, 01:30, then 8-23 will do 0830 to 2330
ref: http://team.macnn.com/drafts/crontab_defs.html
You can restrict the hours you want the job to run.
*/30 0,1,7-23 * * * /usr/bin/php /var/www/update/inv.php
The times will be every 30 minutes until 0130. It won't run at 0200. The next run will be at 0700 and then every 30 minutes.
There's quite a good article here on how to set up the cron:
http://en.wikipedia.org/wiki/Cron

setup cron tab to specific time of during weekdays

I am trying to setup a cron job on a Ubuntu server. We want the cron job to run the script at certain times of the day and on some specific days of the week. For example, we want to setup a cron job that runs the script with the following sequence:
Execute the script every 2 minutes from 9 am to 2 pm during the weekdays.
This is what I have been able to do so far:
*/2 09-14 * * * /path_to_script
What should I do for the weekdays?
Same as you did for hours:
*/2 09-18 * * 1-5 /path_to_script
0 and 7 stand for Sunday
6 stands for Saturday
so, 1-5 means from Monday to Friday
You state 2pm in your requirement, hour range should end at 14 instead of 18 (which is 6pm).
*/2 9-14 * * 1-5 /path_to_script
man crontab
http://unixhelp.ed.ac.uk/CGI/man-cgi?crontab+5
In fact the last hour you want the script to run is 13:00 to 13:59, so you want:
*/2 9-13 * * 1-5 /path_to_script
meaning the first runtime will be 9:00, then 9:02, and so on until 13:58 which will be the last run as 14:00 is not included.

Cron job question

I want to run a php script every 10 minutes, between the hours of 9:30AM - 4:00PM
I googled before asking, and didn't have any success.
Anyone know how to do this? Or point me in the right direction?
Thank you
Try the following three lines in crontab
0,10,20,30,40,50 10-15 * * * # Every 10 minutes for the hours 10am - 3pm
0 16 * * * # 4pm
30,40,50 9 * * * # and 9:30, 9:40, 9:50
Run it from cron in every 10 minutes, check th date in PHP do nothing if it's outside the range.
*/10 * * * * /usr/bin/php /path/to/your/script.php

Resources