Visit Our UNIX and Linux User Community

Shell script to send mail alert

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script to send mail alert
# 1  
Old 11-16-2017
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 :-
echo "Filename is $filename"
MTIME=`find $filename -mmin +10`
if [MTIME is null ]
echo " $filename not modified from last 10 minutes . Please check"
 mail -s "abc.txt not modified "
 echo "$filename is modified "

Moderator's Comments:
Mod Comment 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.

# 2  
Old 11-16-2017
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:
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"

If you know that $filename will never expand to more than one file, you might want something more like:
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"
else	echo "$filename is modified"

Previous Thread | Next Thread
Test Your Knowledge in Computers #188
Difficulty: Easy
Python is an interpreted, high-level, general-purpose programming language, created by Linus Torvalds and first released in 1991
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Shell script to send mail alert

Hi I have below shell script to send mail alert , however I want to add more functionality in this script and that is , script should only check that file between 9 am to 5pm , and if there is no activity in this time 9 am to 5 pm for 2hours then it should give me mail alert, please help... (2 Replies)
Discussion started by: scazed
2 Replies

2. UNIX for Beginners Questions & Answers

Shell script to compare text and send a mail

Hello, Somebody can help me to develop a script for the below requirement I have a 3 files in a directory which was dynamically changed everyday basis. I need a script to fetch the 1pattern of strings in each file. if the three matching pattern is same send a mail with subject as success else... (1 Reply)
Discussion started by: MATHANKUMAR
1 Replies

3. Shell Programming and Scripting

To send a mail through shell script

I want to send a mail through shell script,If it is possible Please give me a code. mail id : (8 Replies)
Discussion started by: kannansoft1985
8 Replies

4. Shell Programming and Scripting

How to automatically send a mail alert if the script errors out

I have a script like this, which calls other scripts from that script: #!/usr/ksh readfile=/home/sample.txt cat $readfile | while read line do file= `echo $line|awk '{print $4}'` if ; then mv $file /home/temp_stage fi (4 Replies)
Discussion started by: ss3944
4 Replies

5. UNIX for Advanced & Expert Users

Send a mail when a shell script is modified

I would like to know, whether is there any command/tool in Linux (something like Oracle Trigger function) to send a mail if a particular shell script has been modified with details like, modification time, modified by, etc. Thanking in advance, (1 Reply)
Discussion started by: apsprabhu
1 Replies

6. Shell Programming and Scripting

Shell script to send a mail

Hi , I need to prepare a script which will check my database with specific to particluar table. If the row count exceeds a certain limit, i need to send a mail to a set of Recipients. Being new to unix, please guide me to complete this task. Advance thanks, Sekar. (4 Replies)
Discussion started by: Sekar1
4 Replies

7. Shell Programming and Scripting

shell script to send a mail

Hi, I need a shell script which runs in the backround for all the 24 hours and send a mail to us regarding the output of the prstat command when the load average increase above certain percent. kindly help me on this...... (1 Reply)
Discussion started by: jayaramanit
1 Replies

8. Shell Programming and Scripting

need to send alert mail

hi, i need to monitor a cron job that runs every 5 mins. if this cron job does not process the request for more than 6 hrs, an alert mail should be sent. how do i achieve this?? (1 Reply)
Discussion started by: smurala
1 Replies

9. Solaris

Shell script to send email alert for core dump

Friends, I am in search for a shell script that is capable of running as a cronjob and have to send out an email when ever there is a CORE DUMP. Please post the hints to achieve my goal. Thanks in advance. (1 Reply)
Discussion started by: rtatineni
1 Replies

10. Shell Programming and Scripting

Send e-mail in Shell script

How to send an error mail from a shell script e.g. mail "Message : here an error message " thanks, Ann. (1 Reply)
Discussion started by: annelisa
1 Replies

Featured Tech Videos