1. Basic usage of crontab:
Edit scheduled tasks
# crontab -e
View all scheduled tasks
# crontab -l
delete crontask
# crontab -r
2. Commands executed on time-sharing days, months and weeks, for example:
①, logbak.sh content:
#!/bin/bash
#打包/var/log
tar -zcf /opt/shell/log-`date +%Y-%m-%d-%H-%M`.tar.gz /var/log
②, Execute logbak.sh once every minute
# crontab -e
* * * * * /opt/shell/logbak.sh
3. The meaning of * - and /n appearing in regular expressions
(1) Use the month to say:
*Equivalent to: 1,2,3,4,6,7,8,9,10,11,12
1-3 is equivalent to: 1,2,3
1,4,7,10 is equivalent to 1,4,7,10
*/3 is equivalent to 1,4,7,10
*/4 is equivalent to 1,5,9
4. If it is May 2019, it will be executed at 23:59 at the end of every three months
59 23 28-31 2,5,8,11 * [ `date -d tomorrow +\%e` -eq 1 ] && /opt/shell/logbak.sh