In this post we will get an email alert if the monitor folder have not receiving any files.
below there is a shell script, if you wan to know more detail on send mail concept you could refer here
--------------Script Start------------------
# cat dir_moni_v2.sh
#!/bin/bash
TO="email_id@email.com"
#MESSAGE=$'Hi There,\nI think today there is no file arrived yet.\n\nThanks\nUnix Support'
PAT=/home/Akil/moni_dir
echo -e "
Hi There,
Date `date`
This is to inform that there is no file received today on this path $PAT
Thanks
Unix Support Team
Automated email
" >/tmp/message.txt
Value=`find $PAT -type f -daystart -ctime 0 -print | wc -l`
if [ $Value -gt 0 ]; then
echo "File received today"
else
echo "File not received today so far so sending mail to the recipient"
tr -d '\015' < /tmp/message.txt | mail -v -s "Directory Monitoring Alert" $TO
#echo $MESSAGE | mail -v -s "Directory Monitoring Alert" $TO
#echo "<Messages>" | mail -s "<Subject of mail>" <Mail_ID>
fi
----------------------Script End---------------------------
output
Scenario 1:
[root@centos ~]# sh dir_moni_v2.sh
File received today
0 Comments