linux计划命令配置文件crontab

文件路径: /etc/crontab

文件格式:

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

# 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
# |  |  |  |  |
# *  *  *  *  *  command to be executed
29  *  *  *  * root run-parts /testcron >> /testcront

上面的东西基本不用管。只需要把需要执行的脚本加到最后一行。格式

mm  hh dd mm we user run-parts /dir

开始时时间,之后是执行脚本时使用的用户身份和执行的命令。看网上说的用户可以省略,但是试了试貌似不行。具体的还要再看看。

第一个字段mm表示分钟,第二个字段hh表示小时。之后分别是天 月 星期 用户 run-parts 目录名 。时间选项支持正则表达式。特殊的 /n 代表每n个时间单位执行一次。

eg.1

/20 3 * * * root run-parts /testcron>>testcront     ;每天的3点,隔20分钟执行一次/testcron目录下的所有可执行脚本。即3:00,3:20,3:40分别执行。


无法执行时的解决思路

      1.查看脚本是否正确。 就是直接在命令行运行脚本。

      2.检查crontab配置文件,时间格式是否正确,有没有多项或者少项

      3.重启crond服务     

service crond restart
      4.检查脚本权限,是否具有可执行权限。如果没有,赋给他可执行权限。   
ls -l filename
chmod 777 filename
      5.如果以上都确定没有问题,就要考虑下是不是环境变量的问题了。看下shell脚本中有哪些命令,特别是类似java,gcc之类的。导入需要的环境变量或者用绝对路径来描述。



猜你喜欢

转载自blog.csdn.net/u011762549/article/details/23948459
今日推荐