定时任务-crontab简单用法

定时任务-crontab简单用法

crotab定时任务:

  • 在服务器上设置定时器,来执行特定的任务脚本,比如php XXX或者 python XXX,或者 go run ***

crontab基本用法:
- crontab时间设置:

# 5个时间表示:分别为以下
* * * *:表示:分、时、日、月、周

crontab -e:

  • 添加crontab定时任务,
  • 例如:设置每分钟执行 进入项目目录,并且php artisan命令
# 设置每分钟执行1次该命令
* * * * * cd ~/dnmp/www/ali-php php artisan schedule >> /dev/null 2>&1

crontab -l:
* 列出当前用户的所有定时任务
- crotab -r:
* 删除当前用户的定时任务


备注:

  • 如果crontab -e添加定时任务失败,可能是当前默认编辑器为vi,需要设置为vim,
# 编辑文件,修改默认编辑器:vim ~/.zshrc  (或者.bash_profile)
export EDTTOR=vim

# 然后,source ~/.zshrc,使其生效,再重新crontab -e来添加定时任务

posted @ 2022-08-21 01:11  alisleepy  阅读(416)  评论(0编辑  收藏  举报