내 요구 사항은 로그 파일에서 문자열을 찾으면 전자 메일을 보내는 것입니다. 그러나 나는 그것을 한 번만 보내야한다. 필자가 작성한 쉘 스크립트는 아래에 붙여 넣습니다. 그러나 조건이 일치하지 않아도 cron 작업을 통해 반복되는 전자 메일을 보냅니다.반복되는 전자 메일을 보내는 셸 스크립트 중지 - 파일 플래그 사용
#!/bin/bash
filexists=""
lbdown=""`enter code here`
if [ -f "/var/run/.mailsenttoremedy" ];
then
filexists=true
else
filexists=false
echo filexists is $filexists
fi
if tail -1000 /usr/ibm/tivoli/common/CTGIM/logs/trace.log | grep "Root exception is java.net.NoRouteToHostException: No route to host"
then
echo error found
lbdown=true
echo lbdown status after if in tail is $lbdown
else
lbdown=false
echo lbdown status after else in tail is $lbdown
fi
if filexists=false && lbdown=true
then
{
mailx -S intrelay.sysco.com -r [email protected] -s "**DEV ALERT**Load Balancer Connection not Available" -v [email protected] < /dev/null
date > /var/run/.mailsenttoremedy
}
fi
if filexists=true && lbdown=true
then
{
echo MAIL ALREADY SENT
}
fi
if lbdown=false
then
rm -f /var/run/.mailsenttoremedy
fi
echo lbdown is $lbdown and filexists is $filexists
에코 출력은 다음과 같습니다
filexists is false
Root exception is java.net.NoRouteToHostException: No route to host
error found
lbdown status after if in tail is true
Null message body; hope that's ok
Mail Delivery Status Report will be mailed to <[email protected]>.
MAIL ALREADY SENT
lbdown is false and filexists is true
내가 "당신"의와 모든 "U"의 교체의 자유를했다. –
노력에 감사 드리며 나는 더 나은 약속을 얻습니다! – suleiman
나는 그것을 마침내 만들었다, 고마워. 만약 내가 잘못 선언했다면 쉘은 문법 오류를 던지지 않고 모든 것을 내부로 전달할 수 있다고 생각합니다. – Bazooka