参考:https://www.cnblogs.com/sxdcgaq8080/p/10730633.html

设置定时任务

查看定时任务:

  1. // 查看定时任务
  2. crontab -l
  3. Options:
  4. -u <user> define user
  5. -e edit user's crontab
  6. -l list user's crontab
  7. -r delete user's crontab
  8. -i prompt before deleting
  9. -n <host> set host in cluster to run users' crontabs
  10. -c get host in cluster to run users' crontabs
  11. -s selinux context
  12. -x <mask> enable debugging

crontab -e

  1. // 编辑任务
  2. crontab -e
  3. // #### 文件内容 ####
  4. SHELL=/bin/sh
  5. PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin/npm
  6. 30 9 * * * /api/index.sh
  7. // 分钟 小时 天 月 周 执行的命令
  8. // minute - 从0到59的整数
  9. // hour - 从0到23的整数
  10. // day - 从1到31的整数 (必须是指定月份的有效日期)
  11. // month - 从1到12的整数 (或如Jan或Feb简写的月份)
  12. // dayofweek - 从0到7的整数,0或7用来描述周日 (或用Sun或Mon简写来表示)
  13. // command - 需要执行的命令(可用as ls /proc >> /tmp/proc或 执行自定义脚本的命令)

查看linux 跑定时后的错误信息

tail -f -n 200 /var/spool/mail/root

shell文件

index.sh

  1. #!/bin/bash -ilex
  2. cd /api && npm run test

软链关联

  1. ln -s /server/node/node-v12.22.1-linux-x64/bin/node /usr/bin/node
  2. ln -s /server/node/node-v12.22.1-linux-x64/bin/npm /usr/bin/npm