[英]sendmail not working in crontab
I am facing issue when I try to execute my script from crontab but when I try to execute manually, it works perfectly fine. 当我尝试从crontab执行脚本时遇到了问题,但是当我尝试手动执行时,它可以很好地工作。
Crontab File Crontab文件
54 * * * * /opt/SP/home/osbadm/scripts/tmp1.sh 2>&1
Sendmail function Sendmail功能
SUBJECT="test"
TO="to@gmail.com" (
echo "TO: $TO"
echo "MIME-Version: 1.0"
echo "Subject: $SUBJECT"
echo "Content-Type: text/html"
cat $EXTRACT_CST_HTML
) | /usr/sbin/sendmail -f from@gmail.com $TO
Can anyone please help me out. 谁能帮我一下。
You can't put a variable assignment before the (
that starts a subshell. If you'd pasted your script into shellcheck.net it would have told you: 您不能将变量赋值放在
(
会启动子shell的(
之前。如果将脚本粘贴到shellcheck.net中 ,它将告诉您:
SC1036: '(' is invalid here. Did you forget to escape it?
SC1036:“(”在这里无效。您是否忘记了对其进行转义?
Also, even if you could, it would only set the variable inside the subprocess's environment, it wouldn't be visible when processing the arguments to sendmail
. 同样,即使可以,它只会在子进程的环境中设置变量,在处理
sendmail
的参数时将不可见。 So put that assignment on its own line. 因此,将该任务放在自己的行上。 Also, a here-doc is an easier way to pass multiple lines of input to
sendmail
. 另外,here-doc是将多行输入传递到
sendmail
的更简便方法。
TO="to@gmail.com"
(
echo "TO: $TO"
echo "MIME-Version: 1.0"
echo "Subject: $SUBJECT"
echo "Content-Type: text/html"
cat $EXTRACT_CST_HTML
) | /usr/sbin/sendmail -f from@gmail.com $TO
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.