I looked at this topic to write a bash script that checks if a file has been modified every 60 min and sends me an email using ssmtp if that is the case. Here is its content (monitoring.sh
):
#!/bin/bash
[[ -z `find /home/myuser/sites/mysite/logs/nginx/error.log -mmin -60` ]]
if [ $? -eq 0 ]
then
echo -e "nothing has changed"
else
echo -e "Something went wrong!" | ssmtp -vvv [email protected]
fi
I then added this script to an hourly cronjob:
01 * * * * /home/myuser/sites/mysite/logs/nginx/monitoring.sh
This does not work at all. Looking at my emails (the sender account that ssmtp uses), the script runs every hour and echoes nothing has changed
even if the error.log
file has been modified.
Maybe using inotifywait
would be more appropriate? Any ideas?
Thanks in advance.
EDIT: If I run this script manually after modifying the error.log
file, it works and I receive the email.