Linux的例行性工作1

[root@server ~]# vim test2.sh        //编辑脚本

1、每分钟执行命令

[root@server ~]# crontab -e

[root@server ~]# crontab -l
* * * * * sh /root/test2.sh
[root@server ~]# ls
anaconda-ks.cfg  cro.txt  dead.letter  test2.sh  testcrondtab.sh

[root@server ~]# cat cro.txt

[root@server ~]# crontab -r
[root@server ~]# crontab -l
no crontab for root
[root@server ~]# ps -aux | grep test2

2、每小时执行

[root@server ~]# crontab -e

[root@server ~]# crontab -l
0 * * * * sh /root/test2.sh
[root@server ~]# ls
anaconda-ks.cfg  cro.txt  dead.letter  test2.sh  testcrondtab.sh
[root@server ~]# cat cro.txt

[root@server ~]# crontab -r
[root@server ~]# crontab -l
no crontab for root
[root@server ~]# ps -aux | grep test2

[root@server ~]# killall

3、每天凌晨3点半和12点半执行脚本

[root@server ~]# crontab -e

[root@server ~]# crontab -l
30 3  * * *  sh /root/test2.sh
30 12 * * *  sh /root/test2.sh

[root@server ~]# ls
anaconda-ks.cfg  cro.txt  dead.letter  test2.sh  testcrondtab.sh
[root@server ~]# cat cro.txt

[root@server ~]# crontab -r
[root@server ~]# crontab -l
no crontab for root
[root@server ~]# ps -aux | grep test2

[root@server ~]# killall

4、每隔6小时,相当于6,12,18,24点半执行脚本

[root@server ~]# crontab -e

[root@server ~]# crontab -l
30 */6 * * * sh  /root/test2.sh

[root@server ~]# ls
anaconda-ks.cfg  cro.txt  dead.letter  test2.sh  testcrondtab.sh
[root@server ~]# cat cro.txt

[root@server ~]# crontab -r
[root@server ~]# crontab -l
no crontab for root
[root@server ~]# ps -aux | grep test2

[root@server ~]# killall

5、30代表半点,8-18/2表示早上8点到下午18点之间每隔2小时执行脚本

[root@server ~]# crontab -e

[root@server ~]# crontab -l
30 8-18/2 * * * sh /root/test2.sh

[root@server ~]# ls
anaconda-ks.cfg  cro.txt  dead.letter  test2.sh  testcrondtab.sh
[root@server ~]# cat cro.txt

[root@server ~]# crontab -r
[root@server ~]# crontab -l
no crontab for root
[root@server ~]# ps -aux | grep test2

[root@server ~]# killall

6、每天晚上9点30重启nginx

[root@server ~]# crontab -e

[root@server ~]# crontab -l
30 21 * * * /usr/bin/systemctl restart nginx

[root@server ~]# ls
anaconda-ks.cfg  cro.txt  dead.letter  test2.sh  testcrondtab.sh
[root@server ~]# cat cro.txt

[root@server ~]# crontab -r
[root@server ~]# crontab -l
no crontab for root
[root@server ~]# ps -aux | grep test2

[root@server ~]# killall

7、每月1和10号凌晨4点45执行脚本

[root@server ~]# crontab -e

[root@server ~]# crontab -l
45 4 1,10 * * sh /root/test2.sh

[root@server ~]# ls
anaconda-ks.cfg  cro.txt  dead.letter  test2.sh  testcrondtab.sh
[root@server ~]# cat cro.txt

[root@server ~]# crontab -r
[root@server ~]# crontab -l
no crontab for root
[root@server ~]# ps -aux | grep test2

[root@server ~]# killall

8、 每周六和周日凌晨1点10分执行命令

[root@server ~]# crontab -e

[root@server ~]# crontab -l
10 1 * * 6 sh /root/test2.sh
10 1 * * 0 sh /root/test2.sh

[root@server ~]# ls
anaconda-ks.cfg  cro.txt  dead.letter  test2.sh  testcrondtab.sh
[root@server ~]# cat cro.txt

[root@server ~]# crontab -r
[root@server ~]# crontab -l
no crontab for root
[root@server ~]# ps -aux | grep test2

[root@server ~]# killall

9、每天18点到23点之间,且每隔30分钟执行一次

[root@server ~]# crontab -e

[root@server ~]# crontab -l

0 18-23 * * * sh /root/test2.sh
30 18-23 * * * sh /root/test2.sh

[root@server ~]# ls
anaconda-ks.cfg  cro.txt  dead.letter  test2.sh  testcrondtab.sh
[root@server ~]# cat cro.txt

[root@server ~]# crontab -r
[root@server ~]# crontab -l
no crontab for root
[root@server ~]# ps -aux | grep test2

[root@server ~]# killall

10、每隔一小时执行一次

[root@server ~]# crontab -e

[root@server ~]# crontab -l

0 * * * * sh /root/test2.sh

[root@server ~]# ls
anaconda-ks.cfg  cro.txt  dead.letter  test2.sh  testcrondtab.sh
[root@server ~]# cat cro.txt

[root@server ~]# crontab -r
[root@server ~]# crontab -l
no crontab for root
[root@server ~]# ps -aux | grep test2

[root@server ~]# killall

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值