Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Shell script to send mail alert

Shell Programming and Scripting


Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 4 Weeks Ago   -   Original Discussion by abhigrkist
abhigrkist's Unix or Linux Image
abhigrkist abhigrkist is offline
Registered User
 
Join Date: Mar 2010
Last Activity: 16 November 2017, 5:33 PM EST
Posts: 28
Thanks: 0
Thanked 1 Time in 1 Post
Shell script to send mail alert

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 :-

Code:
  
 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;

Moderator's Comments:
Shell script to send mail alert Using CODE tags is not hard. Not using CODE tags makes it much harder to read code. Continued refusal to use CODE tags properly may result in your account be locked for a few days or permanently. Please use CODE tags when displaying sample input, output, and code segments as explained in numerous personal emails you have received and as shown below.

Sponsored Links
    #2  
Old Unix and Linux 4 Weeks Ago   -   Original Discussion by abhigrkist
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is offline Forum Staff  
Administrator
 
Join Date: Jul 2012
Last Activity: 14 December 2017, 5:28 PM EST
Location: San Jose, CA, USA
Posts: 10,776
Thanks: 590
Thanked 3,771 Times in 3,219 Posts
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:

Code:
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:

Code:
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

Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Poll for a file. If not present...Send a alert mail phani333 Shell Programming and Scripting 3 05-02-2010 12:05 AM
How to automatically send a mail alert if the script errors out ss3944 Shell Programming and Scripting 4 12-29-2009 05:27 PM
How to use SSH to connect to Primary DB and send alert mail a1_win Shell Programming and Scripting 0 10-27-2008 04:36 PM
need to send alert mail smurala Shell Programming and Scripting 1 03-05-2008 10:17 AM
Shell script to send email alert for core dump rtatineni Solaris 1 08-17-2006 03:33 PM



All times are GMT -4. The time now is 08:39 PM.