我正在尝试根据crontab条目运行脚本。我拥有的脚本在终端中运行良好,但不会按照cron条目自动运行。该脚本只是每小时一次在/ testexport1目录中创建一个空文件。
我使用crontab -e编辑crontab,如下所示:
30 * * * * /bin/bash/ /testexport1/./createfilescript.sh
脚本本身看起来像这样:
[root@centostest testexport1]# cat createfilescript.sh
#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/testexport1
today="$( date +"%Y%m%d" )"
number=0
while test -e "$today$suffix.txt"; do
(( ++number ))
suffix="$( printf -- '-%02d' "$number" )"
done
fname="$today$suffix.txt"
printf 'Will use "%s" as filename\n' "$fname"
touch "$fname"
我在脚本的顶部添加了PATH部分,以指定从何处运行脚本(根据我读过的另一篇文章)。
有什么想法为什么这个crontab条目似乎没有运行脚本?我敢肯定简单的解决方法,但我会绕着圈子转转。
crontab没有运行脚本,因为/bin/bash/
很可能找不到该脚本。应该/bin/bash
改为(注意/
末尾缺少),或bash
系统上的正确路径。
还要确保您在脚本中使用的所有实用程序均在$PATH
您设置的位置中找到。修改路径而不是覆盖路径更为常见,因为系统路径通常包含touch
可能会找到类似内容的目录。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句