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

Unix scripting help

Status
Not open for further replies.

suddie

Technical User
Jan 18, 2002
1
US
I have been given the task of writing a script to archive the logs (to a tar file or better method) periodically. I am fairly new to Solaris,how do I get this done ????
 
Hi Suddie,

As far as i can understand from you question, you want to schedule some sort of activity which should occur periodically say everyday or once in a week or similar. And, that activity should be like archiving the logs when size goes beyond some predefined limit. If that's what you want to do then you can take help of logrotate and cron daemons. Cron is scheduler and logrotate does exctly what you are looking for .

hope this answer your doubt ;-)

regards,
Mahesh
 
As Mahesh says use cron. You may not have logrotate (I haven't). But gzip is also excellent (if you have it) with logfiles , when a file is gzipped it then has a suffix of ".gz". Your cron file can have an entry such as : -

00 04 * * * /opt/logs/zipper.ksh

This means run script at 4am every day. If we look at script, we see: -

cat /opt/logs/zipper.ksh
#!/bin/ksh

# Script to find files in a directory and gzip them.

ACTION="/opt/gzip/gzip"
DIRECTORY="/opt/logs"
#" > /dev/null 2>&1 "
FILENAME="*log*"
EXCLUDEFILE="*.gz"
find $DIRECTORY -name "$FILENAME" ! -name "$EXCLUDEFILE" -mtime +1 -type f -exec $ACTION {} \;

**********

This is just a rough guide, you could tar the logfiles instead, again initiating from cron.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top