Chinaunix

标题: cron执行,但是没有结果? [打印本页]

作者: amonest    时间: 2012-06-19 16:01
标题: cron执行,但是没有结果?
我使用crontab -e命令增加了两项排程:
  1. 59 15 * * * tar zcvf /var/backups/home.tar.gz /home/amonest/python
  2. 59 15 * * * tar zcvf /home/amonest/backup.tar.gz /home/amonest/python
复制代码
备份到/home/amonest目录成功了,备份到/var/backups失败了。

/var/log/cron.log记录到了有执行这两项:
  1. Jun 19 15:59:02 amonest-virtual-machine CRON[5328]: (amonest) CMD (tar zcvf /home/amonest/backup.tar.gz /home/amonest/python)
  2. Jun 19 15:59:02 amonest-virtual-machine CRON[5329]: (amonest) CMD (tar zcvf /var/backups/home.tar.gz /home/amonest/python)
复制代码
是权限问题导致备份/var/backups不成功吗?cron进程不是以root身份运行的吗?


作者: taojie2000    时间: 2012-06-19 16:35
回复 1# amonest


    cron进程不是以root身份运行的吗

    该crontab 任务不再root列表下! 任务里的命令执行权限是普通用户的!
作者: taojie2000    时间: 2012-06-19 16:36
crontab  -l   
作者: amonest    时间: 2012-06-19 16:50
  1. # Edit this file to introduce tasks to be run by cron.
  2. #
  3. # Each task to run has to be defined through a single line
  4. # indicating with different fields when the task will be run
  5. # and what command to run for the task
  6. #
  7. # To define the time you can provide concrete values for
  8. # minute (m), hour (h), day of month (dom), month (mon),
  9. # and day of week (dow) or use '*' in these fields (for 'any').#
  10. # Notice that tasks will be started based on the cron's system
  11. # daemon's notion of time and timezones.
  12. #
  13. # Output of the crontab jobs (including errors) is sent through
  14. # email to the user the crontab file belongs to (unless redirected).
  15. #
  16. # For example, you can run a backup of all your user accounts
  17. # at 5 a.m every week with:
  18. # 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
  19. #
  20. # For more information see the manual pages of crontab(5) and cron(8)
  21. #
  22. # m h  dom mon dow   command

  23. 12 16 * * * tar zcvf /var/backups/home.tar.gz /home/amonest/python
  24. 12 16 * * * tar zcvf /home/amonest/backup.tar.gz /home/amonest/python
复制代码

作者: amonest    时间: 2012-06-19 16:51
回复 2# taojie2000

能修改成root吗?


   
作者: taojie2000    时间: 2012-06-19 17:11
回复 5# amonest


    你会用 命令切换到root 用户不

    然后root用户下添加
作者: amonest    时间: 2012-06-19 17:15
sudo crontab -u root -e?

taojie2000 发表于 2012-06-19 17:11
回复 5# amonest

作者: Shell_HAT    时间: 2012-06-19 19:46
su - root
crontab -e
作者: snow888    时间: 2012-06-19 21:44
或者也可以直接将 /var/backups 目录权限改成你当前用户可读写的权限。
作者: ccxxx    时间: 2012-06-26 02:30
權限問題,可用以下方法確認
另外,一般用户都可以設定cron

12 16 * * * tar zcvf /var/backups/home.tar.gz /home/amonest/python > /tmp/varbackup.log 2>&1




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2