I need to delete the content out of a number of logs


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting I need to delete the content out of a number of logs
# 1  
Old 09-29-2003
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
# 2  
Old 09-30-2003
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 10:15 AM..
# 3  
Old 09-30-2003
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
# 4  
Old 09-30-2003
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.
# 5  
Old 09-30-2003
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 11:06 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to compress and delete the older logs

Hello Guys, Can you please help me with a script which zips the older log files(1-2 weeks) and delete them? I want to run the script manually instead of setting it up in a cron job. Appreciate your help. Regards, Kris (6 Replies)
Discussion started by: kriss.gv
6 Replies

2. Shell Programming and Scripting

Delete logs older than 60 days

i am using HP-UX OS...... delete logs older than 60 days find -mtime +60 | grep -i '.*log' | xargs rm -mtime is nt available in HP-UX, pls tell me other option ? (2 Replies)
Discussion started by: only4satish
2 Replies

3. UNIX for Advanced & Expert Users

Group/Sort logs by thread number

Hello Experts, For the following sample log, can you tell me how I can sort it or group it by thread number. To be specific, I just want to group them together so that its easy to analyize. Thanks. 2012-08-17 00:00:06,369 INFO ExecuteThread: '33' for queue:... (2 Replies)
Discussion started by: samjna
2 Replies

4. Shell Programming and Scripting

To delete logs older than 30 days

I want to write a shell script that deletes all log files in a directory that are older than 30 days except for 3 files: I am using the following command: find /tmp/logs -name "*.log" -mtime +30 -exec rm -f {} \;But this command deletes all the log files. How can i modify this script that... (5 Replies)
Discussion started by: mmunir
5 Replies

5. UNIX for Dummies Questions & Answers

Delete last 10 days logs

Hi Can u please tell me how to delete last 10 days logs .. (9 Replies)
Discussion started by: pb18798
9 Replies

6. Shell Programming and Scripting

how to delete content in a file (delete content only)

Hi Friends I have a file called processLog.txt file processLog.txt --------------- echo "line starts "$LINE suppCode=${LINE:0:3} #gatewayArchive=`scp root@mrp-gateway:/usr/local/apache/data/PLAT/MIMUS/upload/PROD/archive/112042708173000.txt /home/krishnaveni/scripts/tempFolder` #echo... (5 Replies)
Discussion started by: kittusri9
5 Replies

7. UNIX for Advanced & Expert Users

how to archive logs older than 5 days & then delete them?

My code is tar -cvf logs.tar `find /usr/openv/logs/512*.log -mtime +2` && find *.log* -mtime +2 -exec rm {} \; this gives me output as: tar: Missing filenames:confused: (1 Reply)
Discussion started by: timus1980
1 Replies

8. Shell Programming and Scripting

Script to delete logs or take backups under specific user

I have to write a shell script like this-- 1) Utility will be run under the directory owner. 2) This utility will clean files in ABC/logs. And following logs will be backed up or deleted. Dispatcher Logs Middle tier Logs Sage log Sage monitor log Sage db clean up result log Core files ... (12 Replies)
Discussion started by: namishtiwari
12 Replies

9. UNIX for Dummies Questions & Answers

Delete logs every 3 hours

Hi, I want to setup a cronjob that will delete logs every 2 hours. I have script that delete logs per day. but logging is too big and i want to run a conjob that will delete every 2 hours. this is my current command but it deletes on a per day basis. find . -name "*.log*" -o -name... (3 Replies)
Discussion started by: tungaw2004
3 Replies

10. Shell Programming and Scripting

Delete old logs

Hello All, We have a directory where we have old archived logs. They are numbered <logfile>.log.1 till <logfile>.log.100 or more. I just want to keep 10 log files and delete others through the script. Please advise. Thanks, Chiru (4 Replies)
Discussion started by: chiru_h
4 Replies
Login or Register to Ask a Question