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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help me with finding file/emailing in Bash

Status
Not open for further replies.

evild

Technical User
Nov 25, 2002
71
GB
OK, I no practically nothing about scripting in Bash so I need some help.
I want to place a job in the Cron that emails me if the following criteria are met:

a file(s) of format z_u_* is found in directory X

where X is the directory created the day previously [e.g. today directory would be called 'save-2003-10-16' and yesterdays would be called 'save-2003-10-15']


I would like to return an email only when 1 or more of these files exist and the email should contain a listing of those files. I should therefore recieve an email such as this:

"The following files are unprocessed in Task Manager:
z_u_c_r_001.Wed
z_u_c_r_205.Wed
"

Can anyone help me out with this please?
 
#----use perl to calculate yesterdays dir
DIRNAME=$(perl -e '($ss, $mm, $hh, $DD, $MM, $YY) = localtime(time() - 86400);
printf "save-%04d-%02d-%02d", $YY + 1900, $MM + 1, $DD')
cd $DIRNAME || exit 1

#----check for files
TMPFILE=/tmp/zu$$.tmp
ls -1 z_u_* >$TMPFILE
if [ -s $TMPFILE ]
then
( echo The following files are unprocessed in Task Manager:
cat $TMPFILE ) | mailx -s "Unprocessed Files" evild@evild.com
fi
rm $TMPFILE
 
What should I do at the weekends? No directories are created on saturday and sunday so on Monday I would have to check Fridays file.
 
#----use perl to calculate yesterdays dir
#----note that on Mondays yesterday is defined as "three days ago"
case `date +%a` in
Mon) DAYS=3 ;;
*) DAYS=1 ;;
esac
DIRNAME=$(perl -e '($ss, $mm, $hh, $DD, $MM, $YY) = localtime(time() - 86400*'$DAYS');
printf "save-%04d-%02d-%02d", $YY + 1900, $MM + 1, $DD')
cd $DIRNAME || exit 1

#----etc..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top