OS: Raspbian Lite Kernel version:4.19
I am using a script to monitor a service, so that it would start the service if it goes down. I have added it in crontab
and it does a great job. The only problem is that it sends its output to /var/mail/pi
: You have new mail in /var/mail/pi
.
I am afraid that the file will grow too large or that at some point in time it will stop working because of this.
I have found the script online and I don't know what to modify so that it won't send mails:
# vi /var/www/html/service_monitor.sh
#!/bin/bash
serv=DisplayM
sstat=dead
systemctl status $serv | grep -i 'running\|dead' | awk '{print $3}' | sed 's/[()]//g' | while read output;
do
echo $output
if [ "$output" == "$sstat" ]; then
sudo systemctl start $serv
echo "$serv service is now UP !" | echo "$serv service was DOWN. Restarting now on $(hostname)"
else
echo "$serv service is running"
fi
done
These can act like some sort of logs, so I wouldn't mind keeping the /var/mail/pi
file, but it would be nice do keep like, the last 100 entries and delete the others.
What do you think ?