Re: get the timestamp as a log filename

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Tom,

This is a script I cron every night at midnight.
crude but it works without flaw. modify the "date" line to whatever you
want it to be.

hope it helps.

Thanks,
Dave



#!/bin/sh
date=`/bin/date +%b%d%y`
cp /var/logs/messages /var/logs/messages.$date
> /var/logs/messages
chmod 600 /var/logs/messages.$date
cp /var/logs/firewall /var/logs/firewall.$date
> /var/logs/firewall
chmod 600 /var/logs/firewall.$date
gzip /var/logs/firewall.*
mv /var/logs/firewall.* /var/logs/logarchive/
gzip /var/logs/messages.*
mv /var/logs/messages.* /var/logs/logarchive/
exit




On Fri, 2004-01-23 at 06:14, Tom Mitchell wrote:
> On Thu, Jan 22, 2004 at 02:08:56PM -0500, Genti A. Hila wrote:
> > 
> > I think I didn't explain it quite well:
> > I have some log files that are saved from logrotate  hourly.
> > But what i get is something like message.1 messages.2 etc
> > Instead of this i would like to have something like
> > mesagges_04\01\21_14\00
> > So to follow the format  messages_yy\mm\dd\_hour\minute
> 
> Make sure you are not using meta characters in ways the hurt you.
> Commonly \ is used to escape the next character.
> In windowZ  the \ is used as a file separator.
> Same is true of dots '.' which matches any single character.
> Spaces are a bugger in file names too.
> 
> Now I wonder if you intended to build a directory tree:
> with the format  messages_yy/mm/dd/_hour/minute
> 
> > > cp -a file.log intrusion-`date +"%Y.%m.%d_%X"`.log && > file.log
> 
> I have not tried this but I suspect your logrotate configuration file
> could have a postrotate line that in addition to sending a signal to
> the process did something like:
> 
> 	mv logfile.1 logfile-ending-on-`date +"%Y-%m-%d_%R`
> 
> This will cause side effects.  You are no longer rotating the files.
> If you only want 28/29/30/31 files a month then you need log.1 log.2
> ...log.31. type stuff.
> 
> i.e. Now you can run out of space which logrotate is to avoid.
> 
> Compressed files are good, make sure the compression suffix hint is
> not lost.
> 
> 
> -- 
> 	T o m  M i t c h e l l 
> 	mitch48-at-sbcglobal-dot-net
> 




[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux