对我而言,语法似乎写得正确,但我在第16行得到错误....任何想法?
#!/bin/sh
#This is script is meant to be an add on to another one I'm using. Based on the return code output it will mail me the message.
read -p "What is the file name? " variable
rc = $?
ls -al $variable
if [[ $rc != 0 ]]; then
mail -s "$variable script did not complete" email address -- -f email address \
<< EOF Your script has failed with error code $rc << EOF;
elif [[ $rc = 0 ]]; then
mail -s "Your script completed" email address -- -f email address \
<< EOF Your script completed with error code $rc. << EOF;
fi
粘贴似乎搞砸了格式。这是pastebin链接:
答案 0 :(得分:1)
here document起始<< EOF
需要在其自己的行的开头EOF
结束。
mail -s "$variable script did not complete" email address -- -f email address << EOF
Your script $variable has failed with error code $rc.
EOF
如果使用制表符(严格标签)进行缩进,则可以使用:
mail -s "$variable script did not complete" email address -- -f email address <<-EOF
Your script $variable has failed with error code $rc.
EOF
(我很高兴地假设你的mail
命令的语法没问题,虽然我不相信,即使使用GNU getopt()
重新排序选项。如果这两个词{{1} } email address
和email1@us.example.com
或类似的东西,那就更接近了。对于我自己,我仍然更喜欢选择之前的选项。)
我还希望将失败的脚本名称包含在电子邮件正文中以及主题行中。