为什么我的 svn 备份 shell 脚本在终端中工作正常,但在 crontab 中失败?
我在 redhat linux 中有一个 svn 备份脚本。让我们将其称为 svnbackup.sh
当我在终端中运行它时它工作正常。
但是当我将其放入crontab时,即使数据正确备份,它也不会恢复svnserve。
我这是怎么了???
killall svnserve
tar -zcf /svndir /backup/
svnserve -d -r /svndir
I have a svn backup script in a redhat linux. let's it called svnbackup.sh
It works fine, when I run it in terminal.
But when I put it into crontab, it will not bring the svnserve back, even the data is backuped correctly.
What's wrong with me???
killall svnserve
tar -zcf /svndir /backup/
svnserve -d -r /svndir
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通常,“环境”是 cron 作业中的问题,该作业在“终端”运行时有效,但在由 cron 运行时无效。最有可能的是,您的 PATH 未设置为包含保存
svnserve
的目录。使用 svnserve 的绝对路径名或在脚本中适当设置 PATH。
您可以通过在脚本中添加一行(例如:)来进行部分调试,
以准确查看 cron 作业运行时设置的环境量。
Usually, 'environment' is the problem in a cron job that works when run 'at the terminal' but not when it is run by cron. Most probably, your PATH is not set to include the directory where you keep
svnserve
.Either use an absolute pathname for svnserve or set PATH appropriately in the script.
You can debug, in part, by adding a line such as:
to your script to see exactly how little environment is set when your cron job is run.
如果您尝试备份存储库的实时版本,您可能应该使用 svnadmin hotcopy。也就是说,这里有一些可能出现问题的可能性:
svnserve
命令需要一个密码,而 cron 则无法提供该密码。svnserve
命令无限期地阻塞或挂起并被 cron 终止。svnserve
不在 cron 的 PATH 中。假设 svnserve 不接受密码,这可能会解决问题:
现在,使用“backup_and_restart_svnserve.sh”作为要执行的脚本。由于它在后台运行,因此即使 cron 执行下一个任务,它也应该继续运行。
If you are trying to backup a live version of a repository, you probably should be using
svnadmin hotcopy
. That said, here are a few possibilities that come to mind as to what might be wrong:svnserve
command takes a password, which cron, in turn, cannot supply.svnserve
command blocks or hangs indefinitely and gets killed by cron.svnserve
is not in your PATH in cron.Assuming that
svnserve
does not take a password, this might fix the problem:Now, use "backup_and_restart_svnserve.sh" as the script to execute. Since it runs in the background, it should hopefully continue running even when cron executes the next task.