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

how to check log file, copy it and remove contains

Status
Not open for further replies.

franklinmount

Technical User
May 5, 2003
5
US
Can you tell me how I can write a script file where I can look in the /var directory for the log file and copy it to another server and than delete the contains of the log file. I would also like to check for any files larger than 200 mb in size in the /var directory.



We are using a Solaris 5.6 3000 server and the file will be copied to probably a windows server for save keeping for a short time only. The sun server has limited space at this time.



Thanks,



Mario

 
You should look into the logrotate GNU package. I think there's a copy on "sunfreeware.com" for most distributions including one as old as you are running. The logrotate package is specialized at moving logs, and restarting services to use new empty ones through CRON.
 
you could also use logrotate which is provided in most Apache
However it would be pretty easy to script copying the files to a remote location, chop the file down and "rotate the file"

-rcp or rsync the file to another prefered laocation on you other server ( rync can be used accross platforms)
- chop the file down to the last 100 lines ( could be useful to havea bit of history) tail -n100 log.file > log.swap
- clear down the log file ( without removing it as apps or OS may hang) cat /dev/null >> log.file
-file will now have 0 bytes
-squirt back the last 100 lines of your orgional file, cat log.swap >> log.file
-clean up rm log.swap
 
Don't forget to "HUP" or otherwise appropriately signal processes to re-init the log files where appropriate. See individual package manual pages for details. Some packages may not react well to having their log file NULLed from under them without being told that something has changed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top