为什么我的 svn 备份 shell 脚本在终端中工作正常,但在 crontab 中失败?

发布于 2024-10-09 06:15:34 字数 242 浏览 3 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

怀念你的温柔 2024-10-16 06:15:34

通常,“环境”是 cron 作业中的问题,该作业在“终端”运行时有效,但在由 cron 运行时无效。最有可能的是,您的 PATH 未设置为包含保存 svnserve 的目录。

使用 svnserve 的绝对路径名或在脚本中适当设置 PATH。

您可以通过在脚本中添加一行(例如:)来进行部分调试,

env > /tmp/cron.job.env

以准确查看 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:

env > /tmp/cron.job.env

to your script to see exactly how little environment is set when your cron job is run.

一口甜 2024-10-16 06:15:34

如果您尝试备份存储库的实时版本,您可能应该使用 svnadmin hotcopy。也就是说,这里有一些可能出现问题的可能性:

  1. 您已将每个语句作为单独的条目放入您的 crontab 中(无法从 Q 中看出)。
  2. svnserve 命令需要一个密码,而 cron 则无法提供该密码。
  3. svnserve 命令无限期地阻塞或挂起并被 cron 终止。
  4. 命令 svnserve 不在 cron 的 PATH 中。

假设 svnserve 不接受密码,这可能会解决问题:

#! /bin/bash
#  backup_and_restart_svnserve.sh
export PATH=/bin:/sbin:/usr/bin:/usr/local/bin # set up your path here
killall svnserve && \
tar -zcf /svndir /backup/ && \
svnserve -d -r /svndir >/dev/null 2>&1 &

现在,使用“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:

  1. You've put each of those statements as separate entries in your crontab (can't tell from the Q).
  2. The svnserve command takes a password, which cron, in turn, cannot supply.
  3. The svnserve command blocks or hangs indefinitely and gets killed by cron.
  4. The command svnserve is not in your PATH in cron.

Assuming that svnserve does not take a password, this might fix the problem:

#! /bin/bash
#  backup_and_restart_svnserve.sh
export PATH=/bin:/sbin:/usr/bin:/usr/local/bin # set up your path here
killall svnserve && \
tar -zcf /svndir /backup/ && \
svnserve -d -r /svndir >/dev/null 2>&1 &

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文