-bash: crontab: command not found

简介:

[root@foss01 ~]# crontab -e

-bash: crontab: command not found

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


[root@foss01 ~]# crontab -e

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


相关文章
|
7月前
|
关系型数据库 MySQL Shell
【Linux命令】-bash: mysql: command not found
【Linux命令】-bash: mysql: command not found
59 0
|
20天前
|
Shell Linux
重装yum |-bash: yum: command not found
重装yum |-bash: yum: command not found
28 0
|
3月前
|
Linux Shell
mac/linux提示bash: telnet: command not found
mac/linux提示bash: telnet: command not found
|
5月前
|
Shell 应用服务中间件 开发工具
bash: vi: command not found
bash: vi: command not found
|
10月前
|
Shell
bash: accelerate: command not found
bash: accelerate: command not found
1679 3
|
2月前
|
监控 安全 Shell
防止员工泄密的措施:在Linux环境下使用Bash脚本实现日志监控
在Linux环境下,为防止员工泄密,本文提出使用Bash脚本进行日志监控。脚本会定期检查系统日志文件,搜索敏感关键词(如"password"、"confidential"、"secret"),并将匹配项记录到临时日志文件。当检测到可疑活动时,脚本通过curl自动将数据POST到公司内部网站进行分析处理,增强信息安全防护。
113 0
|
5月前
|
Linux Shell Windows
4:Bash shell命令-步入Linux的现代方法
4:Bash shell命令-步入Linux的现代方法
55 0
|
9月前
|
Ubuntu 安全 Linux
不用安装虚拟机,直接在Windows上面运行Linux Bash Shell,嗯!真香!!!
不用安装虚拟机,直接在Windows上面运行Linux Bash Shell,嗯!真香!!!
160 0
|
13天前
|
存储 Shell Linux
Linux Bash 脚本中的 IFS 是什么?
【4月更文挑战第25天】
19 0
Linux Bash 脚本中的 IFS 是什么?
|
11天前
|
Shell Linux
【Linux】Bash支持各种指令选项的原理:命令行参数
【Linux】Bash支持各种指令选项的原理:命令行参数