简体   繁体   English

在 shell 脚本中执行 mailx 命令

[英]executing mailx command in shell script

I have a simple shell script that executes a.sql script.我有一个简单的 shell 脚本,它执行 a.sql 脚本。 When the.sql script has completed, the shell script sends an email to a specified address notifying whether or not the.sql script ran successfully.当 .sql 脚本完成后,shell 脚本会向指定地址发送 email 通知 .ZAC5C74B6184B4B58 脚本是否运行成功。

My problem is that the subject line is being truncated.我的问题是主题行被截断。 I am using a simple IF statement to determine the subject line:我正在使用一个简单的 IF 语句来确定主题行:

grep 'ORA-' $OUTFILE > /dev/null 2>&1
if [ $? = 1 ]; then
    ERRORS=n
    SUBJECT= "$VERSION script successful"
else
    ERRORS=y
    SUBJECT="$VERSION script had error(s)"
fi

This works fine.这工作正常。 However, when I execute the mailx command, the subject line is truncated to "Development" or "Production" depending on the version of the script that has been executed:但是,当我执行 mailx 命令时,根据已执行的脚本版本,主题行会被截断为“开发”或“生产”:

mailx -s $SUBJECT $EMAIL < $MAILFILE

I know the subject line needs to be in double quotes if it includes embedded spaces, but this does not seem to work correctly when assigned to a variable.我知道如果主题行包含嵌入的空格,则它需要用双引号引起来,但这在分配给变量时似乎无法正常工作。

Is there a way around this?有没有解决的办法? Is there a way to escape the double quotes有没有办法逃脱双引号

You need to quote $SUBJECT as you use it, ie您需要在使用时引用$SUBJECT ,即

mailx -s "$SUBJECT" $EMAIL < $MAILFILE

Also there should be no space in也应该没有空间

SUBJECT="$VERSION script successful"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM