samantha
asked on
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
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"
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Tintin,
Thanks a lot for answer. Sorry it took me so long to "accept" the answer.
Sam
Thanks a lot for answer. Sorry it took me so long to "accept" the answer.
Sam
CURRENT=/mylog/current
ARCHIVE=/mylog/archive
ARCHFILE=$ARCHIVE/ulog_wee
files=`find $CURRENT -name "*.log" -mtime +1`
cat $files $ARCHIVE/ulog_weekly_`date
rm -f $files
find $ARCHIVE -name "*.log" -mtime +28 -exec rm -f {} \;
ln -sf $ARCHFILE /mylog/weekly-stat.log