Script to send an alert if a file is present in a directory for 10 min


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to send an alert if a file is present in a directory for 10 min
# 1  
Old 12-29-2009
Script to send an alert if a file is present in a directory for 10 min

hi,

A script which look into a directory and send an alert via a mail. If there is any file exisiting in a directory for more then 10 min.
# 2  
Old 12-29-2009
I suppose there's a number of ways to do it.

Here's one using a cronjob and touch command:

Code:
0,10,20,30,40,50 * * * * /path_to_script/script.sh

Code:
# script.sh
cd $(dirname $0)

ls -1t | awk '
  $1 == "timestamp" { C++; next }
  C { exit 1 }
'

if [ $? -ne 0 ]; then
  echo "Send message here"
fi

touch timestamp

If your find command has the -cmin and -maxdepth options then:
Code:
find /directory_to_check -type f -cmin +10 -maxdepth 1 | grep . > /dev/null

if [ $? -eq 0 ]; then
  echo "Send message here"
fi

Otherwise, use the touch method with find's -newer option negated (! -newer timestamp).

Last edited by Scott; 12-29-2009 at 12:07 PM.. Reason: fixed spelling
# 3  
Old 12-30-2009
please tell me how to use touch and -newer with find as Cmin is not working in my OS
# 4  
Old 12-30-2009
You're welcome!

Code:
cd $(dirname $0)

[ ! -r timestamp ] && touch timestamp && exit

find . -type f ! -newer timestamp | grep . > /dev/null

if [ $? -eq 0 ]; then
  echo "Send message here"
fi

touch timestamp

# 5  
Old 12-30-2009
Thanks Scottn ,

This will not modify or remove or edit anything . As I am working in production
# 6  
Old 12-30-2009
It creates an empty file called timestamp. It doesn't modify anything.

I presume something else, somewhere, will remove or update files within 10 minutes, otherwise you'll get an email every 10 minutes!
Login or Register to Ask a Question

Previous Thread | Next Thread

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. Shell Programming and Scripting

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 :- filename="abc.txt" echo "Filename is $filename"... (1 Reply)
Discussion started by: abhigrkist
1 Replies

3. Shell Programming and Scripting

Total record count of all the file present in a directory

Hi All , We need one help on the below requirement.We have multiple pipe delimited .txt file(around 100 .txt files) present on one directory.We need the total record count of all the files present in that directory without header.File format as below : ... (8 Replies)
Discussion started by: STCET22
8 Replies

4. Shell Programming and Scripting

Systemd errors of missing file “No such file or directory” inspite of file being present

The contents of my service file srvtemplate-data-i4-s1.conf is Description=test service for users After=network.target local-fs.target Type=forking RemainAfterExit=no PIDFile=/data/i4/srvt.pid LimitCORE=infinity EnvironmentFile=%I . . . WantedBy=multi-user.target (0 Replies)
Discussion started by: rupeshkp728
0 Replies

5. Shell Programming and Scripting

List file NOT present in other directory

Dear community, I have one LOG directory with some files. What I need to do is list ONLY the files that are not present in other directory. Using Bash programming! LOG DIR | SYNC DIR FILE1 | FILE1 FILE2 | FILE3 FILE3 | OTHER FILENAME FILE4 ... (9 Replies)
Discussion started by: Lord Spectre
9 Replies

6. UNIX for Dummies Questions & Answers

If File is present send a mail and Archive

Hi , Please help me with a logic, how can I acheive the below. I have a directory /eth/Src/, when ever there is a file(or files) created in this directory, (after the file is completely copied to the /eth/Src/ directory) I need to zip all the files and mail the files to a particular email id... (3 Replies)
Discussion started by: wangkc
3 Replies

7. Shell Programming and Scripting

Script to send alert if any changes are made in crontab.

Hi i want to know how can i write a script to check if any changes are made and send an alert in crontabs . i am using .ksh file extension for writing scripts. (3 Replies)
Discussion started by: honey26
3 Replies

8. Shell Programming and Scripting

Poll for a file. If not present...Send a alert mail

Dear Experts, I have a requirement where a 3rd party system places a file in my folder.I am running on HP UNIX. I would like to have a unix script which will check for the existence of the file. If yes OK. if the file is not placed then it has to send a mail to couple of emails ids saying that... (3 Replies)
Discussion started by: phani333
3 Replies

9. Shell Programming and Scripting

Shell script: If a file stays in a particular directory more than 30 min send an email

Hi , I am new to shell scripting. i have a requirement say i will receive a file in a directory say /xyz.if that file stays in that directory more than 30 min i need to get a mail to my outlook.this should run for every 20 min in crontab. can anyone help me? (8 Replies)
Discussion started by: muraliinfy04
8 Replies

10. Shell Programming and Scripting

Write a script to send alert for some particular hours in a day

Hi All, I have a have a script which checks for some processes whether they are running or not and if they are not running then it send a mail specifying that the processes are not running. This particular script example abc.ksh is runs in a cron like this 0,5,10,15,20,25,30,35,40,45,50,55 * * *... (5 Replies)
Discussion started by: usha rao
5 Replies
Login or Register to Ask a Question