ubuntu – 无法让cron.hourly工作

前端之家收集整理的这篇文章主要介绍了ubuntu – 无法让cron.hourly工作前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我用sudo apt-get install cron安装了cron,以root身份启动它并确认它正在运行
  1. ps -ef

然后我创建了一个包含以下内容的简单脚本:

  1. touch /home/username/cron-test.txt

我使这个脚本文件可执行并将其放入

  1. mv cron-test.sh /etc/cron.hourly

但由于某种原因,它没有被执行,也没有创建文件.我尝试手动运行它,它的工作原理.

我也尝试过其他的cron脚本,但它们似乎不起作用.我错过了什么或者我错误地使用了cron吗?

我的系统是Ubuntu 10.10,我的主机已将其剥离,因此它只安装了几个进程(甚至不是cron).

尝试添加#! / bin / sh作为脚本的第一行并删除扩展名,因此名称为/etc/cron.hourly/cron-test

我记得在哪里读cron不会运行带扩展名的文件,因为当/ ect / crontab具有以下内容时它使用runparts:

  1. # /etc/crontab: system-wide crontab
  2. # Unlike any other crontab you don't have to run the `crontab'
  3. # command to install the new version when you edit this file
  4. # and files in /etc/cron.d. These files also have username fields,# that none of the other crontabs do.
  5.  
  6. SHELL=/bin/sh
  7. PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
  8.  
  9. # m h dom mon dow user command
  10. 17 * * * * root cd / && run-parts --report /etc/cron.hourly
  11. 25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
  12. 47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
  13. 52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )

以上是我的/ etc / crontab在Ubuntu 10.04上的内容,安装了cron(我没有编辑过这个文件)

由于/ etc / crontab文件使用run-parts,因此filename非常严格(感谢Matteo):

  1. run-parts runs a number of scripts or programs found in a single directory
  2. directory. Filenames should consist entirely of upper and lower case letters,digits,underscores,and hyphens. Subdirectories of directory and files with
  3. other names will be silently ignored. Scripts must follow the
  4. #!/bin/interpretername convention in order to be executed. They will not
  5. automatically be executed by /bin/sh. The files found will be run in the
  6. lexical sort order of the filenames.

猜你在找的Ubuntu相关文章