Linux-Crontab命令坑点

版权声明:Summer https://blog.csdn.net/csdnyanglei/article/details/82746085

参考:

  1. Linux中crontab的坑爹环境变量问题
  2.  

   crontab命令,一般运维需要周期性的执行某个脚本时,会使用到该命令。

常用命令

  • #打印已配置的cron任务
    crontab -l
    #进入编辑界面
    crontab -e 
    

环境变量

  • vim /etc/crontab

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root

# For details see man 4 crontabs

# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name  command to be executed

  1. crontab 有自己的PATH路径,默认只加了bin相关的环境变量。
  2. 在执行自己的脚本时,命令有可不在bin中,这时,执行自然会报找不到命令。
  3. 解决方法,推进采用在脚本中加入命令的路径到PATH中,
  • PATH="$PATH:/data/XXX/XXX/bin/"

猜你喜欢

转载自blog.csdn.net/csdnyanglei/article/details/82746085
今日推荐