I would like to get a sample script (ksh or bash, or both so I could see the differences)
What I want to do with the script is send an daily email to myself that contains the following:
- The number of files in a directory
- The total size of the files in that directory
- The contents of a file whos name has yesterdays date ( typical filename = dailyLog.20070216 )
I also want to delete files greater that n days old in a directory
Here is a start.. You need to use find.
# find files older than 10 days and delete them
find /path/to/directory -type f -mtime +10 -exec rm -f {} \;
# count files
echo "file count \c"
find /path/to/directory -type f -print | wc -l
See Perderabo's datecalc script in the FAQ on date arithmetic to get yesterday, tomorrow, etc. Then build a filename, use cat to display the file
Thanks Jim,
I got the code for datecalc, it requires the following format
The code I am using to get yesterdays date is;
curr_time=`date +"%Y-%m-%d"`
yesterday=`./datecalc.ksh -a $curr_time -1`
Also how would I send all of that stuff in an email?