crontab settings with start_time and interval - cron

I have a linux cron job to run. I want to configure its setting. What I have is, start_time for the job and interval after which it should repeat every time. interval is integer and has unit of day. So for example, I want to set up cron job starting on some random date in future and want to run that job periodically after every interval days. I tried to do 0 0 * * */interval but it does not give what I want. Any idea how to achieve it?

I think you may want something like
0 0 */interval * * /your/command
Basically switching day of week for day of the month. As for the random start date, that will have to be done somewhere else I think, like with a shell script which edits the cron file at a certain point etc.
EDIT:
This little script would allow you to edit the cron file.
#!/bin/sh
crontab -l > tempcron
echo "00 00 * * * /bin/ls" >> tempcron #just an example cron
crontab tempcron
rm tempcron

Related

run cron job between 00:00 - 00:02 - 04:00 - 23:59 on every hour

I want to run a cron job between 0:00am - 02:00am - 04:00am and 23:59am on every hour.
I want to know if this is the correct syntax.
0,0-59 0-2,4-23/1 * * *
Thanks!
No, your syntax is not correctly formatted.
You can use:
0 0 0/1,0-2 ? * *
This will run according to the following rules:
At second :00, at minute :00, every hour between 00am and 02am,
and every hour starting at 00am, of every day
You can check CRON syntax with an explanation at:Cron Expression Generator & Explainer.
Also, I think this site has a really good breakdown to help understand what each section of the CRON expression relates to.
Edit: I just noticed you had the second part about running at 23:59. For this you will need to set up a second CRON job:
0 59 23 * * ? *
Use Case: At 23:59:00pm every day

Azure cron expression for once every hour starting at specific time

I'm trying to create scheduled job, using cron expression but Azure is not accepting any of the expression I create. For example I want to start a job that runs every hour starting at 3:30
0 30 3/1 * * * *
But according to Azure this is invalid. According to other sites this is valid.
Do you mean every hour starting from 3:30am and ending at midnight (11:30pm) every day?
This should work:
0 30 3-23 * * *
Or from 3:30pm to 11:30pm:
0 30 15-23 * * *
Update:
If you want your first run to happen at a specific time and then recur every n minutes, then Azure Webjob Cron won't help, I think. They do not support extended syntax. In fact, they use modified ncrontab implementation, so you can try to dig into that.
But - if you have a specific need to start cron at a specific time and run indefinetely, you have several options:
Option 1: Use Azure Scheduler. It has Start At Specific Time Setting
Option 2: Add a check to your code that will check date/time and then run Cron every 30 minutes.
You could separate clearing/setting an inhibition flag into separate jobs:
0 30 * * * * if [ ! -e /tmp/inhibitor ] ; then job.sh ; fi
0 0 0 * * * touch /tmp/inhibitor
0 29 3 * * * rm -f /tmp/inhibitor

Can you confirm my crontab line is right

I want to set a cron job to run at 00h15 every Friday. Is this the correct way to do this:
15 0 * * 5
Use this kind of website to validate your crons:
http://crontab.guru/#15_0___5

cron expression for every hour starting from specific time

I am able to schedule using this cron expression using nodejs cron-job every one hour (starting from "now").
But I need to set q cron every one hour starting from a specific time. E.g let's say starts from 3:30 AM. can this be done?
The / character allows you to give two expressions to a cron part. The first is a "starting at" argument and the second is "every X units". So, a cron that will run every hour, starting at 03:30 (I.e., at 03:30, 04:30, 05:30, etc.) would look like this:
0 30 3/1 * * * *
You can try this:
30 3/1 * * * * *
Just to add to Mureinik's answer, just "starting at" on the first argument is non-standard and it may not work with every cron. The standard format should be
startingAt-endingAt/forEvery
example: 30 3-23/1 * * *

I need help using cronjob

I'm trying to write a cron job to run automatically a PHP file after 30 days. The PHP file has write permission 777.
Here is my code:
* * * */30 * php -f /var/www/virtual/my_domain_name.com/htdocs/./file.php > /dev/null 2>&1
But this is not working, I got no errors.
When i try:
* * * * * php -f /var/www/virtual/my_domain_name.com/htdocs/./file.php > /dev/null 2>&1
The script works, then it executes the file every second from.
Any ideas?
Putting */30 in the 4th field would cause the job to run only in the 30th month of the year, and every 30 months thereafter during the year -- i.e., never.
Putting */30 in the 3rd field (day of month) would cause it to run on the 30th day of each month (and on the 60th, 90th, ... day of the month if there were such a thing). And given the *s in the other fields, it would run once a minute on that day -- and never in February. I doubt that that's what you want.
If you want a job to run once a month, that's easy:
0 0 12 * * php ...
This will run the job at midnight on the 12th day of each month. Adjust the first two fields to pick a different time and the third to pick a different day.
There is no syntax for running a job once every 30 days. If that's really what you want, you can schedule the job to run once every day:
0 0 * * * php ...
and then have the job itself determine whether the current day is a multiple of 30.

Resources