The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to delete content in a file (delete content only) kittusri9 Shell Programming and Scripting 5 05-15-2008 10:12 AM
how to archive logs older than 5 days & then delete them? timus1980 UNIX for Advanced & Expert Users 1 02-08-2008 02:53 AM
Script to delete logs or take backups under specific user namishtiwari Shell Programming and Scripting 12 01-25-2008 02:31 AM
Delete logs every 3 hours tungaw2004 UNIX for Dummies Questions & Answers 3 12-09-2007 04:22 AM
Delete old logs chiru_h Shell Programming and Scripting 4 09-14-2007 03:33 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-29-2003
Registered User
 

Join Date: Sep 2003
Posts: 2
Stumble this Post!
I need to delete the content out of a number of logs

I'm just starting out in scripting (taking online classes) but I need to know how to clean out (delete) the content of a number of logs. All of the files end in 'trc'. Does anyone have a script or command (SED or AWK) I can use?

Julie
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 09-30-2003
google's Avatar
Moderator
 

Join Date: Jul 2002
Location: Atlanta
Posts: 740
Stumble this Post!
The best way to learn scripting is to get on the command line and try a few things! This script trims a log and removes others. Be patient and you will learn. Also, take a look at the board rules, no posting homework questions!

#!/bin/ksh
# name: cleanup
# this is a genral cleanup script
echo "starting cleanup...wait"
rm /usr/local/apps/log/*.log
tail -40 /var/adm/mesages >/tmp/messages
rm /var/adm/messages
mv /tmp/messages /var/adm/messages
echo "finished cleanup"

Last edited by google; 09-30-2003 at 06:15 AM.
Reply With Quote
  #3 (permalink)  
Old 09-30-2003
Registered User
 

Join Date: Sep 2003
Posts: 2
Stumble this Post!
Thanks for the reply. (This is a work question). I need to remove the content of multiple logs within a directory but not the log itself. Processes are conected and if I remove the logs I have Inode issues. So, I was hoping to find a script or command that would allow me to use a wildcard and would remove the content of the logs.

Thanks

Julie
Reply With Quote
  #4 (permalink)  
Old 09-30-2003
mbb mbb is offline
Registered User
 

Join Date: Aug 2001
Location: UK
Posts: 103
Stumble this Post!
A point to be careful of here.

Simply removing entries from a log file or removing a log file whilst its logging process is still running might not release disk space.

You may have to stop and restart the logging process (whatever that process is) before the disk space is available for other uses and other processes.
__________________
Senior Analyst/Programmer
Reply With Quote
  #5 (permalink)  
Old 09-30-2003
google's Avatar
Moderator
 

Join Date: Jul 2002
Location: Atlanta
Posts: 740
Stumble this Post!
If you want the remove the contents of the logs without removing the file itself then echo a blank to the log, but dont append to the log, overwrite the log instead. This will overwrite all contents of the log with a blank space. The result is an empty log.

for $LOG in ` ls -1 /log-path/*.trc`
do
echo "" > $LOG
done

Last edited by google; 09-30-2003 at 07:06 AM.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 05:40 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0