【发布时间】:2014-11-27 06:11:33
【问题描述】:
每次执行特定的 cronjob 时都会收到以下邮件。当我直接调用它甚至从 cron 调用时,被调用的脚本运行良好。所以我得到的消息不是一个实际的错误,因为脚本完全按照它应该做的事情。
这是 cron.d 条目:
* * * * * root /bin/bash -l -c "/opt/get.sh > /tmp/file"
还有 get.sh 脚本本身:
#!/bin/sh
#group and url
groups="foo"
url="https://somehost.test/get.php?groups=${groups}"
# encryption
pass='bar'
method='aes-256-xts'
pass=$(echo -n $pass | xxd -ps | sed 's/[[:xdigit:]]\{2\}/&/g')
encrypted=$(wget -qO- ${url})
decoded=$(echo -n $encrypted | awk -F '#' '{print $1}')
iv=$(echo $encrypted | awk -F '#' '{print $2}' |base64 --decode | xxd -ps | sed 's/[[:xdigit:]]\{2\}/&/g')
# base64 decode input and save to file
output=$(echo -n $decoded | base64 --decode | openssl enc -${method} -d -nosalt -nopad -K ${pass} -iv ${iv})
if [ ! -z "${output}" ]; then
echo "${output}"
else
echo "Error while getting information"
fi
当我不使用 bash -l 语法时,脚本会在 wget 过程中挂起。所以我的猜测是它与wget有关并将输出放入stdout。但我不知道如何解决它。
【问题讨论】:
-
是的,我确实使用通过 http_proxy 变量设置的代理。
-
哦,等等,我想我们已经到了这里。我通过 /etc/profile.d 中的文件设置代理,该文件包含在 /etc/profile 中。也许这在“正常” cronjob 调用期间不可用?
-
确保当您的 bash(用户 root)不是登录 shell 时设置该变量。