I'm looking at a crontab on a linux server and came accross the following line
*/1 * * * * /path/to/file
To me this means run the cron every 1 minute right?
What makes it different from this?
* * * * * /path/to/file
I'm fairly new to Linux crontab so hopefully this isn't a dumb question.
'*/1' is a step definition and means every minute; it is identical to the second format.
If you would want to do something every 2 hours, you could do this:
* */2 * * * /path/to/file
See: (search for the word "Ranges")
man 5 crontab
There's no difference. The cron scheduler sees them both as 1 minute from the last run.
Related
My cron job is working fine if I write
*/15 16 * * * setup.sh
It is called cron job at every 15th minute like 0,15,30,45 and again 0.
I need to run 15th minute of a specific time
Ex: crontab(12)
12/15 16 * * *
This is correct by https://crontab.guru/ but showing a non-standard cron job may not work on some crontab.
And also not working in my case.
Help me to sort it out. Thanks in advance
The "12/" part is what makes it non-standard.
You could rewrite it as:
12,27,42,57 16 * * *
And that should work.
I have a scree.php file in the path:
xxx/.../Home/scree.php
I want to execute it per 5 minutes, and make sure it is thread-safety. How to do that?
I am under XShell.
It can be done using crontab.
Type "crontab -e" in your terminal.
Paste in the following code:
*/5 * * * * php /Home/scree.php
Exit out of your editor.
Learn more about crontab here.
You can edit the crontab in XShell:
crontab -e
Then in the file, you should add the code:
*/5 * * * * root usr/bin/php xxx/.../Home/scree.php
Then esc :wq out of the file.
If it shows:
crontab: installing new crontab
means success.
I would like to run several scripts every half-hour. This obviously would work with this line
*/30 * * * * script.sh
My question now is how I would be able to run several of these at different times. As in, script.sh to run 5 minutes before script2.sh which then is 5 minutes before script3.sh. If that shouldn't be possible, any way to ensure that they aren't executed within 5 minutes of each other would suffice.
I did see solutions to do this with a script or otherwise programmatic. If cron can't be used for the job a "not possible" is what I'm looking for as the answer.
*/30 is equivalent to 0,30. If you use the latter syntax you can simply use 5,35 for another job to offset it from the first.
For example, for three jobs you could do:
0,30 * * * * script1.sh
5,35 * * * * script2.sh
10,40 * * * * script3.sh
Note that if script1.sh takes longer than 5 minutes to run, there will still be overlap between script1.sh and script2.sh. If you really must avoid that, you should probably consider lock files (using e.g. flock).
I have three scripts and want every one of them to run every 3 minutes, but in way that every minute a different script is running.
for example
00:00 script1 is executed
00:01 script2 is executed
00:02 script3 is executed
00:01 script1 is executed
Is there a way to make this work via crontab in Debian?
At the moment I have it like this:
*/3 * * * * php /Scripts/script1.php &> /dev/null
*/3 * * * * php /Scripts/script2.php &> /dev/null
*/3 * * * * php /Scripts/script3.php &> /dev/null
but this would run all the scripts all 3 minutes
There might be fancier ways, but the dead simple way is just to list out the minutes you want them to run on (and the rest would of course be * for hours, days, etc):
0,3,6,9,12,15,18,21,24,27...
1,4,7,10,13,16,19,22,25,28...
2,5,8,11,14,17,20,23,26,29...
Call a wrapper script every minute.
This wrapper script looks at (minutes % 3) and calls the correct script using the remainder.
Only one line in cron: nice.
EDIT: New thoughts
You can skip the wrapper by introducing an ugly crontab line.
I would go for the wrapper (cleaner crontab, place to set and export variables,
additional control statements), but I think you should know about the possibilities.
Make the testfiles x0, x1 and x2 in /tmp, chmod +x them, with the content
echo $(date) $0 >> /tmp/x.out
Make a crontab line
* * * * * /tmp/x`echo "$(date '+\%M') \% 3" | bc`
Wait 5 minutes (maybe get coffee black for me?) and look at /tmp/x.out.
Remove the crontab entry and the new /tmp/x* files.
In my hosting i have a section for cron job like this:
(source: site-helper.com)
The PHP script is called "croned.php", which I want it to run every 10 minutes.
What I will fill in every field?
I tried but it didn't work.
Note: the full path to the script is: /home/axelzd/domains/hellodom.com/public_html/croned.php
Put */10 in the minutes whilst putting * in all other fields.
Usually you can use commas to separate the cron minutes/hours etc. - 0,10,20,30,40,50 in your minute field (but I can't guarantee your admin will take it - I know Plesk does) and * in all others . The command is more tricky, but something like this should do /usr/bin/wget -q -t 5 --delete-after URL_TO_YOUR_CRON or php PATH_TO_YOUR_PHP_FILE_ON_THE_SERVER
try this
*/10 * * * * <command_to_be_invoked>