1

是否可以通过无论何时 schedule.rb 文件在 crontab 中设置 PATH 或 SHELL 变量?

# here I want to set the PATH and SHELL variable somehow

every 3.hours do
  # some cronjob
end

在我的 capistrano 部署之后,我希望在我的 crontab 中得到这个输出:

SHELL=/bin/bash
PATH=/usr/local/bin:/usr/local/sbin:/sbin:/usr/sbin:/bin:/usr/bin:/usr/bin/X11
# some cronjobs
4

2 回答 2

2

好的,看来我找到了解决方案。我在这里找到它:https ://gist.github.com/jjb/950975

我会在测试后更新这个答案

我必须把它放到我的 schedule.rb

# If your ruby binary isn't in a standard place (for example if it's in /usr/local/bin,
# because you installed it yourself from source, or from a thid-party package like REE),
# this tells whenever (or really, the rails runner) where to find it.
env :PATH, '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin'
于 2014-05-23T17:06:48.423 回答
0

在设置等时运行 zenity 时DISPLAY,您已经在这样做了。LANG

如果要设置 shell,请在/home/username/script/script1.shusing的第一行设置#!/bin/bash

如果要设置路径,一种方法是在运行命令之前设置它:

5    9-20 * * * PATH=/usr/local/bin:/usr/local/sbin:/sbin:/usr/sbin:/bin:/usr/bin:/usr/bin/X11 /home/username/script/script1.sh > /dev/null

另一种/更好的方法是创建一个简单的包装脚本,如下所示:

#!/bin/bash
export PATH=/usr/local/bin:/usr/local/sbin:/sbin:/usr/sbin:/bin:/usr/bin:/usr/bin/X11

# Absolute path to this script
SCRIPT=`readlink -f $0`
# Absolute directory this script is in
SCRIPTPATH=`dirname $SCRIPT`

#make sure we are in the same directory as the script1.sh - this is useful in case the script assumes it is running from the same directory it's in and makes relative directory/file references
cd $SCRIPTPATH



##run final script, and pass through all parameters that were passed to wrapper script.
/home/username/script/script1.sh "$@"
于 2014-05-23T16:37:33.287 回答