- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: How to trim log file with out restarting syslo...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-25-2010 03:30 AM
тАО06-25-2010 03:30 AM
Re: How to trim log file with out restarting syslogd
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-25-2010 03:39 AM
тАО06-25-2010 03:39 AM
Re: How to trim log file with out restarting syslogd
> I would like to trim to 1or 2MB ..
In the above example: (Details given ..)
F = Filename to trim = user_log
You may be want to keep last few lines of the log files , say last 200 lines you want to keep.
Keep = k = 200
Total_lines = t (Automatically calculated.)
Delete/Trim Lines = d = (Automatically calculated.)
- So here is the command you need to run to trim the file to just 200 line , or any minimum number you desire:
# cd /var/adm/syslog/
# F=user_log ; k=200 ; t=`sed -n "$=" $F`; d=`expr $t - $k` ; perl -i -ne "print unless 1 .. $d" $F
# wc -l user_log
200 user_log
- Now to see the size , you can use :
- # ls -l user_log #It should have trimmed to a small size in KB ).
Enjoy , Have fun!,
Raj.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-25-2010 04:12 AM
тАО06-25-2010 04:12 AM
Re: How to trim log file with out restarting syslogd
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-25-2010 04:16 PM
тАО06-25-2010 04:16 PM
Re: How to trim log file with out restarting syslogd
@ Raj:
Using 'perl -ni -e...' to perform an inplace file update will *NOT* work for trimming files where a (daemon) process is required to continue to update the trimmed file without a restart. Perl performs this slight-of-hand by renaming the original input file and thus changing its inode. Thus, the process continues to write to the *old* file, and any logging to the new file doesn't occur.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-25-2010 06:18 PM
тАО06-25-2010 06:18 PM
Re: How to trim log file with out restarting syslogd
> Perl performs this slight-of-hand by renaming the original input file and thus changing its inode.
- This is really true.
Thanks for correcting. Yes, perl changes the inode of the file ,so log update doesn't happen further to that file, unless the daemon is restarted again. James, Thanks again for the valuable input.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-25-2010 07:05 PM
тАО06-25-2010 07:05 PM
Re: How to trim log file with out restarting syslogd
What i use to do is copy this file with time stamp and trim this file to 0 bytes
like
#cp -p user_log user_log.24Jun2010
#>user_log
Suraj
- « Previous
-
- 1
- 2
- Next »