oldstring='<tr><th> Report </th><td bgcolor="#FF0000"><font color="#FFFFFF"> STOPPED</font></td></tr>'
newstring='<tr><th> Report </th><td bgcolor="#FF0000"><font color="#FFFFFF"> STOPPED-ON-REQUIREMENT</font></td></tr>'
#the above strings are from HTML File
TIME=$(date '+%H%M%S')
if [ $TIME -ge 110000 ] -a [ $TIME -le 160000 ]
then
grep -rl STOPPED /temp/report.html | xargs sed -i "s/$oldstring/$newstring/g"
if grep -q STOPPED "/temp/report.html"; then
( echo "Subject: Servers || Alert Server Stopped - Servers HEALTH REPORT";echo "To: rajesh@xyz.com";echo "From:abc@xyz.com"; echo "MIME-Version: 1.0"; echo "Content-Type: text/html"; echo "Content-Disposition: inline";echo "Importance: High"; cat //tmp/health.html ; ) | sendmail -t
else
( echo "Subject: Servers || Servers HEALTH REPORT";echo "To: rajesh@xya.com";echo "From:abc@xyz.com"; echo "MIME-Version: 1.0"; echo "Content-Type: text/html"; echo "Content-Disposition: inline"; cat //tmp/health.html ; ) | sendmail -t
fi
elif grep -q STOPPED "//tmp/health.html"; then
( echo "Subject: Servers || Alert Server Stopped - Servers HEALTH REPORT";echo "To: rajesh@xya.com";echo "From:abc@xyz.com"; echo "MIME-Version: 1.0"; echo "Content-Type: text/html"; echo "Content-Disposition: inline";echo "Importance: High"; cat //tmp/health.html ; ) | sendmail -t
else
( echo "Subject: Servers || Servers HEALTH REPORT";echo "To: rajesh@xya.com";echo "From:abc@xyz.com"; echo "MIME-Version: 1.0"; echo "Content-Type:text/html"; echo "Content-Disposition: inline"; cat //tmp/health.html ; ) | sendmail -t
fi
我正在尝试grep一个HTML文件,如果找到STOPPED单词,我将其替换为基于时间的其他需求单词。并将报告发送给我的团队。
但是当我尝试运行时,我会得到以下不同的错误
./tempsendmail.sh[8]: syntax error at line 14 : `<' unexpected
./tempsendmail.sh[18]: syntax error at line 30 : `)' unexpected
答案 0 :(得分:-1)
我得到了答案,我就这样实现了(适用于Linux):
newstring = grep -E STOPPED- /tmp/temp1.txt&lt; - 因为我不能用特殊字符分配整行,我必须将该行放在临时文件和grep中,将其指定为变量 oldstring = grep -v REQUIREMENT /tmp/tempS1.txt< - 与上述相同
TIME = $(日期&#39; +%H%M%S&#39;)
如果[&#34; $ TIME&#34; -gt 104000 -a&#34; $ TIME&#34; -lt 191000] 然后 sed -i&#34; / Report123 / c \ | $ newstring |&#34; /tmp/temp1.txt&lt; - 这将找到&#34; Report123&#34;并用newstring替换整行