如何运行 cron 作业以每分钟执行一次?

Tah*_*ram 7 cron rhel

我正在尝试在目录中创建一个名称中带有时间戳的/home目录。我以 root 用户身份创建了以下 cron 作业,但它没有运行。我究竟做错了什么?

以下是我使用 root 用户权限创建的 cron 作业。

[root@bvdv-emmws01 home]# crontab -l
* * * * * /home/test.sh
Run Code Online (Sandbox Code Playgroud)

以下是内容/home/test.sh更新:添加了目录的完整路径。

[root@bvdv-emmws01 home]# cat /home/test.sh 
#!/bin/bash
mkdir /home/test_$(date -d "today" +"%Y%m%d%H%M%S")
Run Code Online (Sandbox Code Playgroud)

许可/home/test.sh

[root@bvdv-emmws01 home]# ls -ltr /home/test.sh
-rwxrwxrwx 1 root root 58 Dec  2 12:58 /home/test.sh
Run Code Online (Sandbox Code Playgroud)

我已经更新了/etc/crontab文件。该文件现在具有以下内容:

[root@bvdv-emmws01 home]# 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

* * * * * root /home/test.sh
Run Code Online (Sandbox Code Playgroud)

状态 crond daemon

[root@bvdv-emmws01 home]# service crond status
crond (pid  1910) is running...
Run Code Online (Sandbox Code Playgroud)

Ant*_*hon 9

使用创建crontab -e和可列出的crontabcrontab -l不应为命令指定用户。您的条目应为:

* * * * * /home/test.sh
Run Code Online (Sandbox Code Playgroud)

或者,也可以将您所在的行/etc/crontab改为。

来自man 5 crontab(部分示例系统 CRON 文件):

# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.
Run Code Online (Sandbox Code Playgroud)

注意最后一句话。