how to get the files in unix using while loop

January 9, 2012 at 23:04:41
Specs: Windows XP
i have a folder in a unix box and the file are present as A-2011-01-10.csv.the folder get updated daily as per the cureent date format.i need to find where the file is present in the folder and if it is present by get i can get the file to my another unix server.If the file is not present then it shall send a mail.

Please provide a solution how to get the file using while loop and if not prsent then it shall send a mail.


See More: how to get the files in unix using while loop

Report •

#1
January 10, 2012 at 09:04:08
This assumes your unix server has sendmail or some other mail client setup. Let me know if you have any questions:

#!/bin/ksh

# Look for a file A-2012-01-10.csv based on todays date
mflag=0
ls -1 A-$(date +%Y-%m-%d).csv 2> /dev/null |while read myfile
do
   echo "place your copy command here for $myfile"
   mflag=1
done

# did not find the file
if [ $mflag -eq 0 ]
then
   mailx -s "your subject" address@whatever.com << MESS
Your mail message
MESS
fi


Report •
Related Solutions


Ask Question