• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 359
  • Last Modified:

Bourne Shell script to process log files

Hi,

Could someone please help me with a shell script task I need to conquer?  I am new to Unix and have no idea where to start.  Here is my problem:

I have the following directories:
/mylog
/mylog/current/
/mylog/archive/

Inside /mylog/current/, there are log files created for each day, say "ulog_20050416.log" to "ulog_20050423.log". (Note the filename ends with Date Stamp.)  I need a bourne shell script which will be run by a "cron" job once a week on Sunday.  This script should concatenate the previous weeks' log files(Sun. to Sat.) into one weekly file say "ulog_weekly_20050416.log", then move it to /mylog/archive/.  The script then deletes those daily log files.  Note that the cron job runs on Sunday, so this Sunday's log file should remain untouched until next Sunday the script runs.  

Inside the /mylog/archive, I only want to keep the weekly log file for 4 weeks.  Any weekly file that is older than 4 weeks should be deleted by the script.  

Finally, a symbolic link should be created/updated in the /mylog directory, say "/mylog/weekly-stat.log", which should point to the weekly log file that was just created above in /mylog/archive/.   This way, the person who fetches the weekly file can use the same name "weekly-stat.log" every week.

I will really really appreciated if someone can help me with this?  Or point me to the right direction.  Thanks in advance.

Sam
0
samantha
Asked:
samantha
  • 2
1 Solution
 
TintinCommented:
#!/bin/sh

CURRENT=/mylog/current
ARCHIVE=/mylog/archive
ARCHFILE=$ARCHIVE/ulog_weekly_`date +%Y%m%d`.log

files=`find $CURRENT -name "*.log" -mtime +1`

cat $files $ARCHIVE/ulog_weekly_`date +%Y%m%d`.log

rm -f $files

find $ARCHIVE -name "*.log" -mtime +28 -exec rm -f {} \;

ln -sf $ARCHFILE /mylog/weekly-stat.log
0
 
TintinCommented:
Correction:

#!/bin/sh

CURRENT=/mylog/current
ARCHIVE=/mylog/archive
ARCHFILE=$ARCHIVE/ulog_weekly_`date +%Y%m%d`.log

files=`find $CURRENT -name "*.log" -mtime +1`

cat $files >$ARCHFILE

rm -f $files

find $ARCHIVE -name "*.log" -mtime +28 -exec rm -f {} \;

ln -sf $ARCHFILE /mylog/weekly-stat.log
0
 
samanthaAuthor Commented:
Hi Tintin,

Thanks a lot for answer. Sorry it took me so long to "accept" the answer.

Sam
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now