I want the cron job to run the script weekly basis - cron

I am trying to setup a cron job on a Ubuntu server. I want the cron job to run the script on weekly basis. Problem is - It should be a working day, If im mentioning it with time interval, it fails during weekoffs - Need an Schedular Exp which has to work weekly only on working days at office hours.(9am to 9pm)max.
Want to Execute the script every week #6 pm during the weekdays. It Can be Mon to Fri.

Step1
sudo apt-get install cron
systemctl status cron
Step2
Configure the cron job:
crontab -e
Select an editor of your choice
0 0 * * 0 /path/to/command
Syntax: minute hour day-of-month month day-of-week command.
Day-of-week goes from 0-6 where 0 is Sunday.
Save it.

Related

Cron job periods

I would like to run the cron job every 20 minutes between 9 AM and 11 PM and once an hour after 11 PM until 9 AM.
cron job settings
I created 2 cron jobs for the same script to achieve my goal. Did I do it correctly?
Thank you.
Not really. There are two issues:
you run the script also on 23:20 and 23:40
you run the script twice from 09:00 till 23:00 every hour.
The way to do it is:
*/20 9-22 * * * command
0 0-8,23 * * * command
You can validate this using crontab guru

Add crontab job after at job is executed

I am pretty new to the VPS running on Linux 19.04.
I have already had a at job which will be executed on January 27 13:00:00 2020.
I am just wondering if there is any possible way to add a new crontab job after the at job is executed?
Let say I want to add a crontab job 0 0 * * * /usr/bin/pm2 restart Bot, which will restart the Bot running with pm2 at 00:00 every day.
If I want to manually add the crontab job is no problem, I just crontab -e and edit it in nano. But I want it to automatically add the crontab job after the at job is executed, or after 1 minute of at job is executed.

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

Run immediately then every 4 hours in cron

How do you write a cron job which immediately run, then run on every hour divisible by 4? Say I started the script at 13:25, the job fires up right away, then the next run would be at 16:00, 20:00, 00:00 and so on.
For the first immediate run, just execute the command manually. Then set your cron up like this to have it execute continuously every 4th hour
0 */4 * * * yourCommand
This will run yourCommand every 4 hours (00:00, 04:00, 08:00......)

how to schedule a cron job to run every second week

I have a cron command which I using currenly for run daily. I want to make it run every second week Monday morning 9AM. please advice
0 0 * * * curl -s -L web.url.com/user/adminNotifier
you can use this site to generate Cron command
http://crontab-generator.org/
hope this helps you

Resources