我将文件grive.sh添加到/etc/cron.daily中,但该命令似乎没有运行。我也把它复制到/etc/cron.hourly,但是我的Google目录没有改变。该文件只有三行:
#! /bin/sh
cd /media/james/Seagate Expansion Drive/GD
grive权限是只读的,所以我会更新这些权限。
我使用了/etc/cron.hourly# chmod u+rwx grive.sh,但是当我检查Nautilus中的文件的权限时,它们没有变化--我不知道为什么。
我可以从终端手动运行grive,文件在本地和在线同步。
root@james-Streacom:/etc/cron.hourly# grep CRON /var/log/syslog
Feb 1 09:17:02 james-Streacom CRON[8696]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Feb 1 10:17:01 james-Streacom CRON[10958]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Feb 1 11:17:01 james-Streacom CRON[12897]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Feb 1 12:17:01 james-Streacom CRON[15307]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Feb 1 13:17:01 james-Streacom CRON[17043]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Feb 1 14:17:01 james-Streacom CRON[17354]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Feb 1 15:17:01 james-Streacom CRON[17705]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
root@james-Streacom:/etc/cron.hourly# cd / && run-parts --report /etc/cron.hourly
root@james-Streacom:/# bash -c "cd / && run-parts --report /etc/cron.hourly"
root@james-Streacom:/#请注意,这可能是放进去后,cron的工作就不起作用了/etc/cron.hourly/中定义的工作。crontab -e的重复,我只是在进行这些步骤。
我将echo test >/tmp/foobar.tmp添加到脚本的最后一行。
root@james-Streacom:/etc/cron.hourly# grep 'cron\.hourly' /etc/crontab
17 * * * * root cd / && run-parts --report /etc/cron.hourly/temp/foobar.tmp不存在。
我试图实际运行# cd /media/james/Seagate Expansion Drive/GD,并得到了错误-su: cd: too many arguments。然后,我将脚本中的cd行更改为cd /media/james/"Seagate Expansion Drive"/GD。
$ echo test >/tmp/foobar.tmp确实创建了包含测试的文件。# echo test2 >/tmp/foobar.tmp用test2覆盖测试。
发布于 2018-02-01 11:28:42
除了原始脚本中未引用的空格(您似乎已经更正了)之外,这个问题可能与您的脚本的命名有关。
根据DEBIAN SPECIFIC部分的man cron:
As described above, the files under these directories have to be pass some sanity checks including the following: be executable, be owned by root, not be writable by group or other and, if symlinks, point to files owned by root. Additionally, the file names must conform to the filename requirements of run-parts: they must be entirely made up of letters, digits and can only contain the special signs underscores ('\_') and hyphens ('-'). Any file that does not conform to these requirements will not be executed by run-parts. For example, any file containing dots will be ignored. This is done to prevent cron from running any of the files that are left by the Debian package management system when handling files in /etc/cron.d/ as configuration files (i.e. files ending in .dpkg-dist, .dpkg-orig, and .dpkg-new).
因为grive.sh的名字中有一个点,所以run-parts会忽略它。
发布于 2018-02-01 10:19:14
我不太明白您的问题,尽管根据我的经验,当您将一些命令添加到脚本中并放入一个cronjob时,它们并不像预期的那样工作。
我首先将它添加到/etc/cron.d/test中的新文件中,如下所示(我将每5分钟配置一次,以获得一些日志以供测试):
# m h dom mon dow user command
*/5 * * * * root [DIR_TO_SCRIPT]/grive.sh >> /var/log/grivesh.log 2>&1请参阅/var/log/grivesh.log中的stdout,一旦对其进行了分析,就可以每小时配置一次cronjob (例如,每小时5分钟):
# m h dom mon dow user command
5 * * * * root [DIR_TO_SCRIPT]/grive.sh >> /var/log/grivesh.log 2>&1在/etc/cron.hourly/中有必要使用它吗?难道你不准备让它在/etc/cron.d/或crontab中为您的用户?
致以敬意,
https://askubuntu.com/questions/1001933
复制相似问题