天天看点

-bash: crontab: command not found

[root@foss01 ~]# crontab -e

-bash: crontab: command not found

[root@foss01 ~]# yum install -y vixie-cron

no crontab for root - using an empty one

crontab: installing new crontab

[root@foss01 ~]# chkconfig --list crond   -查看是否是开机启动

crond           0:off 1:off 2:on 3:on 4:on 5:on 6:off

[root@foss01 ~]# 

Linux配置定时任务,大家都知道使用crontab这个系统功能,但有时候我们需要区分用户执行,下面就直接说一下2种方法的区别:

方法1:

使用命令 crontab -e 然后直接编辑定时脚本。

这样执行以后,属于用户自定义的,会被写到 /var/spool/cron 目录下,生成一个和用户名一致的文件,文件内容就是我们编辑的定时脚本。

如:

[root@foss01 ~]# cd /var/spool/cron/

[root@foss01 cron]# ll

total 4

-rw------- 1 root root 70 Mar 31 10:36 root

[root@foss01 cron]# cat root

* */2 * * * /usr/sbin/ntpdate 192.168.20.37 >> /root/ntpdate.log 2>&1

方法2:

使用命令 vi /etc/crontab 编辑定时脚本。

系统级的)做系统级配置我们会直接配置 /etc/crontab

[root@nhrnormal ~]# cat /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

# |  |  |  |  |

# *  *  *  *  * user-name command to be executed

59 23 * * *   root /root/qingli.sh

(用户级的)一般还是建议大家使用 crontab -e ,这样系统也会帮着检查我们配置的脚本语法。

本文转自aaa超超aaa 51CTO博客,原文链接:http://blog.51cto.com/10983441/1758738

继续阅读