如何将所有 bash 环境变量传递给 cron

发布于 2024-11-16 08:15:31 字数 70 浏览 4 评论 0原文

给定的 crontab 条目会出现错误,原因是它无法从 bash 读取所有环境变量。我想知道如何将所有这些信息传递给 cron

A given crontab entry gives errors and the reason is that it can not read all env variables from bash. I wonder how could I pass all this info to cron

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

可遇━不可求 2024-11-23 08:15:31

我过去使用过的一个技巧是为特定用户打开一个 bash 会话,然后键入:

env >$HOME/.cronenv

您可以从 cron 脚本中获取此文件(或者直接从 crontabs 中获取,如果您正在运行可执行文件) t 改变),类似于:

. $HOME/.cronenv

这当然是使用热核弹头杀死一只苍蝇。您确实应该确定脚本所需的最低限度,然后使用它。

One trick I've used in the past is to open up a bash session for the specific user and just type:

env >$HOME/.cronenv

You can this source this file from your cron scripts (or directly from the crontabs if you're running an executable you can't change) with something like:

. $HOME/.cronenv

This is, of course, using a thermonuclear warhead to kill a fly. You should really identify the bare minimum that your script requires and just use that.

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