Cron jobs 04-25-2017, 03:53 PM
#1
Cron jobs are the first thing any *nix user looking to automate something will pull out of their toolkit. You need periodic server cleanup? Done. You want to piss off your friends with spam on the 6th and 18th of every month? Sure, done. Your coffee pot at work has telnet and you want a cup at 7:30 every morning? Done.
A quick explanation on how it works: there's a cron daemon that runs on systems using cron jobs that checks for hourly, daily, weekly, and monthly tasks in the /etc/cron.<interval>/ directories (as well as /etc/cron.d/ for jobs defined by crontab), and runs the commands in them at the specified intervals.
The full syntax of a cron job when defined with crontab (usually "crontab -e", you can change the default editor from vi to whatever you want with the VISUAL environment variable) looks like the following, explained below it.
The asterisk (*) normally used as a default represents every possibility for that interval (e.g. * in the hour spot means every hour), so the default 5 asterisks runs the script every minute, of every hour, of every day, etc.
Specifying a number (n) within the noted ranges will run the script on the n-th of that interval (e.g. 30 in the minute spot runs the script on the 30 minute mark of every hour), not every n of that interval, that comes later.
You can use a comma-separated list of numbers (no spaces) or a range (a to b, typed a-b) to specify multiple "n"s for a given interval (e.g. 3,7,11 in the month spot will match March, July, and November. 5-10 in the month spot will match May to October).
Next, you can use "i/n" to run the script n times in i. That's a little weird to explain, so a good example would be 0-10/2 in the minute spot. This will run the script every 2 minutes in the first 10 of whatever the rest of the pattern matches. Additionally, you can use */n to run every n of the interval.
For the weekday column, abbreviations of the days of the week can be used (e.g. mon, tue, wed, etc...), and for the month column, the same can be done with months (jan, feb, mar, etc...).
Instead of doing any of the above, you can use the @yearly, @monthly, @weekly, @daily, and @hourly keywords to run the desired script at those intervals, and the @reboot keyword for whenever the system boots.
Cron intervals are weird, I'm not denying that. It takes some getting used to, so here's some to practice with.
A quick explanation on how it works: there's a cron daemon that runs on systems using cron jobs that checks for hourly, daily, weekly, and monthly tasks in the /etc/cron.<interval>/ directories (as well as /etc/cron.d/ for jobs defined by crontab), and runs the commands in them at the specified intervals.
Syntax
The full syntax of a cron job when defined with crontab (usually "crontab -e", you can change the default editor from vi to whatever you want with the VISUAL environment variable) looks like the following, explained below it.
Code:
* * * * * myscript.sh
| | | | | |
| | | | | \--> script/command
| | | | \----> weekday [0-7] (0 and 7 are sunday)
| | | \------> month [1-12]
| | \--------> date [1-31]
| \----------> hour [0-23]
\------------> minute [0-59]Intervals
The asterisk (*) normally used as a default represents every possibility for that interval (e.g. * in the hour spot means every hour), so the default 5 asterisks runs the script every minute, of every hour, of every day, etc.
Specifying a number (n) within the noted ranges will run the script on the n-th of that interval (e.g. 30 in the minute spot runs the script on the 30 minute mark of every hour), not every n of that interval, that comes later.
You can use a comma-separated list of numbers (no spaces) or a range (a to b, typed a-b) to specify multiple "n"s for a given interval (e.g. 3,7,11 in the month spot will match March, July, and November. 5-10 in the month spot will match May to October).
Next, you can use "i/n" to run the script n times in i. That's a little weird to explain, so a good example would be 0-10/2 in the minute spot. This will run the script every 2 minutes in the first 10 of whatever the rest of the pattern matches. Additionally, you can use */n to run every n of the interval.
For the weekday column, abbreviations of the days of the week can be used (e.g. mon, tue, wed, etc...), and for the month column, the same can be done with months (jan, feb, mar, etc...).
Instead of doing any of the above, you can use the @yearly, @monthly, @weekly, @daily, and @hourly keywords to run the desired script at those intervals, and the @reboot keyword for whenever the system boots.
Practice
Cron intervals are weird, I'm not denying that. It takes some getting used to, so here's some to practice with.
Spoiler:
Code:
* * * * *Spoiler: answer
Every minute
Spoiler:
Code:
0 */3 * * mon-friSpoiler: answer
Once every 3 hours on weekdays
Spoiler:
Code:
*/15 9,17 * * *Spoiler: answer
Every 15 minutes at 9 AM and 5 PM
Spoiler:
Code:
30 6 * 1-11 1-5Spoiler: answer
6:30 AM on weekdays (Monday to Friday) from January to November
Spoiler:
Code:
11 11,23 11 11 *Spoiler: answer
11:11 AM and PM on the 11th of November
(This post was last modified: 04-25-2017, 05:08 PM by Inori.)
It's often the outcasts, the iconoclasts ... those who have the least to lose because they
don't have much in the first place, who feel the new currents and ride them the farthest.
don't have much in the first place, who feel the new currents and ride them the farthest.

















![[+]](https://sinister.li/images/modern/collapse_collapsed.png)




![[Image: 9H83e18.png]](https://i.imgur.com/9H83e18.png)






![[Image: ezgif_com_gif_maker.gif]](http://image.ibb.co/jc44HH/ezgif_com_gif_maker.gif)