2021年2月23日 作者 zeroheart

shell 定时任务

1.选择一个编辑器

select-editor

2.创建一个定时任务脚本

vim cron.sh

#!/bin/bash
top -b -c -n 1 -d 1 > /tmp/top-$(date "+%Y-%m-%d_%H-%M-%S")

3.创建定时任务

crontab -e

*/1 * * * * sh /path/to/script.sh

4.重启一下

sudo service cron restart  
# crontab基本格式
# +---------------- minute  分钟(0 - 59)
# |  +------------- hour    小时(0 - 23)
# |  |  +---------- day     日期(1 - 31)
# |  |  |  +------- month   月份(1 - 12)
# |  |  |  |  +---- week    星期(0 - 7) (星期天=0 or 7)
# |  |  |  |  |
# *  *  *  *  *  要运行的命令