一个URL寻找一个bash脚本,将完成以下内容:(前www.google.com)脚本来检查特定文本
- 检查URL
- 寻找一个特定的文本字符串
- 如果它存在,它什么都不做
- 如果它不,然后发送一封电子邮件,提醒有人
我尝试了下面的脚本,它没有做任何事情,我没有收到任何电子邮件或任何东西。
#!/bin/sh
URL="URL"
TMPFILE=`mktemp /string_watch.XXXXXX`
curl -s -o ${TMPFILE} ${URL} 2>/dev/null
if [ "$?" -ne "0" ];
then
echo "Unable to connect to ${URL}"
exit 2
fi
RES=`grep -i "StringToLookFor" ${TMPFILE}`
if [ "$?" -ne "0" ];
then
echo "String not found in ${URL}" | mail -s "Alert" [email protected]
exit 1
fi
echo "String found"
exit 0;
如果你只是在命令行输入'mail -s'Alert'your @ email',会发生什么?你收到一封电子邮件吗? –
@JimGarrison脚本只是挂在那里,我被迫关闭/停止它。 – Ahmad
不,如果您在脚本之外的命令行运行“mail -s”Alert“your @ email',会发生什么? –