【发布时间】:2014-01-28 18:34:12
【问题描述】:
]# crontab -l
#ROOT CRONTAB test
#22 15 * * * root my_date=`date +\%Y-\%m-\%0e_\%H:\%M:\%S`; /usr/bin/pg_dumpall -U postgres > /home/apache/tactic_backup/postgresDb_${my_date}
53 13 * * * root /home/apache/tactic_custom_tools/backup.sh
]# 更多 /home/apache/tactic_custom_tools/backup.sh
#!/bin/bash
/usr/bin/pg_dumpall -U postgres > /home/apache/tactic_backup/postgresDb/`date +\%Y-\%m-\%0e_\%H:\%M:\%S
它不会在 /home/apache/tactic_backup/postgresDb/ 下创建任何东西
但是当我以 root 身份运行脚本或命令时,它可以正常工作并执行所需的操作。但是通过 crontab 它不会 上面的 crontab 是针对 root 的。即使在日志中它也显示它运行(或如此)
Jan 28 13:40:01 bjweb01 crond[13935]: (root) RELOAD (/var/spool/cron/root)
Jan 28 13:40:01 bjweb01 CROND[34555]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Jan 28 13:40:01 bjweb01 CROND[34556]: (root) CMD (root /home/apache/tactic_custom_tools/backup.sh)
Jan 28 13:46:47 bjweb01 crontab[34743]: (root) LIST (root)
Jan 28 13:49:53 bjweb01 crontab[34814]: (root) BEGIN EDIT (root)
Jan 28 13:50:01 bjweb01 CROND[34818]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Jan 28 13:52:11 bjweb01 crontab[34814]: (root) REPLACE (root)
Jan 28 13:52:11 bjweb01 crontab[34814]: (root) END EDIT (root)
Jan 28 13:53:01 bjweb01 crond[13935]: (root) RELOAD (/var/spool/cron/root)
Jan 28 13:53:01 bjweb01 CROND[34887]: (root) CMD (root /home/apache/tactic_custom_tools/backup.sh)
知道我错过了什么吗?
【问题讨论】:
-
pg_dumpall是否可能需要postgres参数提供完整路径? -
pg_dumpall: 无法连接到数据库“template1”:致命:角色“root”不存在你得到这个
-
当您尝试使用完整路径或尝试使用
/usr/bin/pg_dumpall -U postgres时,您会得到这个?我会尝试在脚本中添加touch /tmp/testfile以查看脚本是否正在执行。这样您就可以准确地看到问题出在哪里。 -
它就像我的脚本,它的 /usr/bin/pg_dumpall -U postgres > /home/apache/tactic_backup/postgresDb/`date +\%Y-\%m-\%0e_\% H:\%M:\%S 脚本在以 root 身份在 shell 上手动运行时工作并创建文件,但不是通过 crontab
-
奇怪。您是否尝试过提供二进制文件的路径来执行脚本?
* * * * * /bin/bash /path/to/script.sh