HI Guys,
I am writing one shell script to send the mail alert to some email id's if the file not modified in last 10 mins but its not working, I believe MTIME is null string is wrong . can you please assist me on this.
script :-
filename="abc.txt"
echo "Filename is $filename"
MTIME=`find $filename -mmin +10`
if [MTIME is null ]
then
echo " $filename not modified from last 10 minutes . Please check"
mail -s "abc.txt not modified " abc.xxx@com
else
echo "$filename is modified "
exit;
When you start a thread in this forum it is always a good idea to tell us what operating system and shell you're using. Otherwise, we may make assumptions that apply to some operating system and shells that cannot possibly work in your environment...
If filename
might contain pattern matching characters (and might therefore match more than one file) which might be supplied as a command line operand, you might want to try something more like:
filename=${1:-abc.txt}
echo "Filename is $filename"
find $filename -mmin +10 | while read -r file
do echo "$file not modified from last 10 minutes. Please check!"
mail -s "$file not modified" abc.xxx@com
done
If you know that $filename
will never expand to more than one file, you might want something more like:
filename="abc.txt"
echo "Filename is $filename"
MTIME=$(find "$filename" -mmin +10)
if [ -z "$MTIME" ]
then echo "$filename not modified in last 10 minutes. Please check"
mail -s "$filename not modified" abc.xxx@com
else echo "$filename is modified"
fi