lundi 4 décembre 2017

Notification when service is down (Bash)

Sup i got some problems with bash script. Im trying to make script which send email, when service is down. Mail will be sended only one time when service is down. Where is mistake? Script doesnt rsend mail and remove file, when service is active.

here is my code

#!/bin/bash
service=xrdp
file=/script/empty

while n=1;
do
if (( $(ps -ef | grep -v grep | grep $service | wc -l) <= 0 )) && [ !  -f $file ];
then touch $file &&  mail -s ""$service" is down" admin < /dev/null && n=0;
else n=0;
fi
done;
while n=0
do
if (( $(ps -ef | grep -v grep | grep $service | wc -l) > 0 ))
then rm -rf $file && n=1
done;

Aucun commentaire:

Enregistrer un commentaire