crontab -e 不起作用

crontab -e 不起作用

我正在用一个每分钟运行一次的简单脚本测试 crobtab(粘贴下面的 temp.sh),但它不起作用

# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h  dom mon dow   command

* * * * * /home/temp/temp.sh

临时文件

backup_dir=`date "+%Y-%m-%d-%H-%M-%S"`
echo $backup_dir >> $PWD/temp.txt

权限详情:

-rwxrwxrwx 1 temp temp    73 Mar 14 21:55 temp.sh
-rw-rw-r-- 1 temp temp   100 Mar 14 21:59 temp.txt

笔记:当我手动运行“/home/temp/temp.sh”时,它正在运行并在 temp.txt 文件中打印日期

任何帮助都值得感激。谢谢

Linux:Ubuntu 18

答案1

crontab -e文件应该是:

*/1 * * * * /home/temp/temp.sh

确保 temp.sh 具有使用 创建 temp.txt 的执行权限chmod +x temp.sh

还将 shebang 和 cd 添加到 temp.sh 文件中的输出目录中

#!/bin/sh
backup_dir=`date "+%Y-%m-%d-%H-%M-%S"`
cd /home/temp/
echo $backup_dir >> $PWD/temp.txt

答案2

您是否检查过是否/etc/cron.allow存在?在这种情况下,用户“temp”必须列在其中。除此之外,/var/log/syslog还应包含任何相关的错误/状态消息。

相关内容