HPE Community read-only access December 15, 2018
This is a maintenance upgrade. You will be able to read articles and posts, but not post or reply.
Hours:
Dec 15, 4:00 am to 10:00 am UTC
Dec 14, 10:00 pm CST to Dec 15, 4:00 am CST
Dec 14, 8:00 pm PST to Dec 15, 2:00 am PST
cancel
Showing results for 
Search instead for 
Did you mean: 

Check directory

 
Son dam bi
Advisor

Check directory


I have a directory , there are many file will be created to it , I would like to write a script to check if there is a file its file extension is .txt AND it is elder than 5 days , then move the file to xxx directory and send me mail to tell me the file name , can advise what can i write it ? thx in advance.

4 REPLIES
Johnson Punniyalingam
Honored Contributor

Re: Check directory

Last contribution date: October 29, 2009
I have assigned points to 0 of 61 responses to my questions.

Problems are common to all, but attitude makes the difference
Johnson Punniyalingam
Honored Contributor

Re: Check directory

DESTDIR="/abcd"
find $DESTDIR -name "*.log" -mtime +5 -exec ll {} \; >

Above will check file with extension .txt list and send output to log.txt

Problems are common to all, but attitude makes the difference
F Verschuren
Esteemed Contributor

Re: Check directory

do get the mail sometinge like:

find $DESTDIR -name "*.log" -mtime +5 |while read line
do
mv /OLDDIR/$line NEW_DIR
echo $line >> /tmp/tempfile
done
cat /tmp/tempfile |mail name@Qdomain.com
R.K. #
Honored Contributor

Re: Check directory

Hi..

Try this..though I have not tested it.

for FILE in `find /Source_dir -mtime +5 -exec ls {} \; | grep txt`
do
mv $FILE /path_of_xxx
write_your_mail_syntax
done
Don't fix what ain't broke