Schedule jobs on Ubuntu

  • 首先编辑任务表
$ crontab –e
# Edit this file to introduce tasks to be run by cron.

# 

# Each task to run has to be defined through a single line

# indicating with different fields when the task will be run

# and what command to run for the task

# 

# To define the time you can provide concrete values for

# minute (m), hour (h), day of month (dom), month (mon),

# and day of week (dow) or use '*' in these fields (for 'any').# 

# Notice that tasks will be started based on the cron's system

# daemon's notion of time and timezones.

# 

# Output of the crontab jobs (including errors) is sent through

# email to the user the crontab file belongs to (unless redirected).

# 

# For example, you can run a backup of all your user accounts

# at 5 a.m every week with:

# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/

# 

# For more information see the manual pages of crontab(5) and cron(8)

# 

# m h  dom mon dow   command
  • 参数说明:

    • m:分钟,范围0~59
    • h:小时,范围0~23
    • dom:day of month,几号,1~31
    • mon:月,范围1~12
    • dow:day of week,周几,1~7
    • command:要执行的命令
  • 增加记录

@reboot sudo /etc/init.d/shadowsocks start
0 3 * * * sudo /etc/init.d/shadowsocks restart

以上第一行表示系统启动的时候启动ss,第二行表示每天凌晨3点重启一次ss。

  • 常用配置

每分钟运行一次

*/1 * * * *
  • 保存后重启服务生效
sudo /etc/init.d/cron restart