Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

message script 1

Status
Not open for further replies.

adaaje

Technical User
May 26, 2006
60
AU
Hi guys,

I'm trying to create a script to tell me if there's any file coming into my directory...

So the idea is if there's any file coming to my directory, it will give me the message about this file just came in...

in pseudo code I think I'll get the latest time of directory and if there's any file coming, the directory time will be changed after that I have to print to message to let me know which file just came in.

Anyone can help me with unix code ??

THX in advance
 
What about counting the number of files in the directory

ls |wc -l|awk '{print $1} > number

store this value and compare it next time your script runs

a=`ls |wc -l|awk '{print $1}`

if [ $a > $number ] ; then
mailx -s "New file found" you@you.com
echo $a > number
fi

You could use diff / uniq to include the name of the file.



Mike

"A foolproof method for sculpting an elephant: first, get a huge block of marble, then you chip away everything that doesn't look like an elephant."

 
Hi mrn,

Thanks for your response, but I need to run this script and keep it running. I think I need looping process here to check every 60 seconds.

So your script is good but I need dynamic one, which If I run the script :

./checkingfiles.ksh

It will keep running, and checking the directory every 60 seconds whether there is any files coming in until I stop it manually or reach certain number lets say 200 files.

Thanks man in advance,

 
you could run it from cron say

crontab -e

* 9-17 * * * your_script.ksh

Or to do it in a loop

----------------------------------
count=0
a=`ls |wc -l|awk '{print $1}`

until [ $count = 201 ] ; do

if [ $a > $number ] ; then
mailx -s "New file found" you@you.com
echo $a > number
fi

sleep 60

(( count += 1 ))

done



Mike

"A foolproof method for sculpting an elephant: first, get a huge block of marble, then you chip away everything that doesn't look like an elephant."

 
Just noticed a mistake.

add

number=`cat number` below a=

Mike

"A foolproof method for sculpting an elephant: first, get a huge block of marble, then you chip away everything that doesn't look like an elephant."

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top