Sponsored Content
Top Forums Shell Programming and Scripting Shell script to send mail alert Post 303007452 by Don Cragun on Thursday 16th of November 2017 06:42:46 PM
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:
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

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Send e-mail in Shell script

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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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 moveFiles.sh extract.sh 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

8. 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 : upload.xxx@example.com (8 Replies)
Discussion started by: kannansoft1985
8 Replies

9. 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

10. 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
IS_READABLE(3)								 1							    IS_READABLE(3)

is_readable - Tells whether a file exists and is readable

SYNOPSIS
bool is_readable (string $filename) DESCRIPTION
Tells whether a file exists and is readable. PARAMETERS
o $filename - Path to the file. RETURN VALUES
Returns TRUE if the file or directory specified by $filename exists and is readable, FALSE otherwise. EXAMPLES
Example #1 is_readable(3) example <?php $filename = 'test.txt'; if (is_readable($filename)) { echo 'The file is readable'; } else { echo 'The file is not readable'; } ?> ERRORS
/EXCEPTIONS Upon failure, an E_WARNING is emitted. NOTES
Keep in mind that PHP may be accessing the file as the user id that the web server runs as (often 'nobody'). Safe mode limitations are not taken into account before PHP 5.1.5. Note The results of this function are cached. See clearstatcache(3) for more details. Tip As of PHP 5.0.0, this function can also be used with some URL wrappers. Refer to "Supported Protocols and Wrappers" to determine which wrappers support stat(3) family of functionality. Note The check is done using the real UID/GID instead of the effective one. This function may return TRUE for directories. Use is_dir(3) to distinguish file and directory. SEE ALSO
is_writable(3), file_exists(3), fgets(3). PHP Documentation Group IS_READABLE(3)
All times are GMT -4. The time now is 08:35 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy