Unix administration - -n days ago

This is Interesting: Free IT Magazines  
Home > Archive > Unix administration > January 2007 > -n days ago





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author -n days ago
thomasriise

2006-12-18, 7:22 am

Hi,

I need to go e.g. 30 days back in time, and then archive files from
that day.

For example - today it's 2006/12/18. How can I go back to 2006/11/18?

What I need is just variables - date +%Y%m%d - just -n days ago. I
don't have GNU date.

Running Sun 5.8.

Thanks.

Andy Johnson

2006-12-18, 1:20 pm

find is capable of locating files created/modified n days ago (or more
than/less than n if you use +/-)

find /somedir -mtime 30 -print


"thomasriise" <thomasriise@gmail.com> wrote in message
news:1166446578.052590.313110@79g2000cws.googlegroups.com...
> Hi,
>
> I need to go e.g. 30 days back in time, and then archive files from
> that day.
>
> For example - today it's 2006/12/18. How can I go back to 2006/11/18?
>
> What I need is just variables - date +%Y%m%d - just -n days ago. I
> don't have GNU date.
>
> Running Sun 5.8.
>
> Thanks.
>



Steve Cousins

2006-12-18, 1:20 pm

thomasriise wrote:

>Hi,
>
>I need to go e.g. 30 days back in time, and then archive files from
>that day.
>
>For example - today it's 2006/12/18. How can I go back to 2006/11/18?
>



find / -mtime -30 > /tmp/archive_files
tar cvTf /tmp/archive_files archive.tar

The first line creates a listing of the files to be backed up that have
been modified within the last 30 days.
The second line creates the archive (using Gnu tar) based on that file.

try "man find" for other ways of doing things like this but the above
method is what I use.

Adjust accordingly.

Good luck,

Steve

thomasriise

2006-12-19, 7:32 am

Hi, and thanks for your answer.

Yes, I know the find and the m/atime command - but what I actually want
to is to go to my logdir 30 days ago.

Today I can e.g. make variables
date +%Y%m%d = 20061219 - and that is the name of the logdir. How do I
do the same 30 days ago?

George Baltz

2006-12-19, 7:32 am

On Tue, 19 Dec 2006 01:22:39 -0800, thomasriise wrote:

> Hi, and thanks for your answer.
>
> Yes, I know the find and the m/atime command - but what I actually want to
> is to go to my logdir 30 days ago.
>
> Today I can e.g. make variables
> date +%Y%m%d = 20061219 - and that is the name of the logdir. How do I do
> the same 30 days ago?


I don't have a Solaris system to check its date command, but on my AIX
boxes I can manipulate the 'TZ' environment variable to slew the date
output:

$ date
Tue Dec 19 13:19:47 CUT 2006
$ TZ=240 date
Sat Dec 9 13:19:53 2006


--
George Baltz N3GB
Computer Sciences Corp Rule of thumb: ANYthing offered
@NOAA/NESDIS/IPD by unsolicited email is a hoax,
Suitland, MD 20746 ripoff, scam or outright fraud.

Doug Freyburger

2006-12-19, 1:23 pm

thomasriise wrote:
>
> Today I can e.g. make variables
> date +%Y%m%d = 20061219 - and that is the name of the logdir. How do I
> do the same 30 days ago?


I remember a non-Solaris system having a date command that could
take relative expressions like "30 days ago" on their command line.
Sounds like it's time to download some GNU versions ...

Warren Block

2006-12-19, 7:25 pm

Doug Freyburger <dfreybur@yahoo.com> wrote:
> thomasriise wrote:
>
> I remember a non-Solaris system having a date command that could
> take relative expressions like "30 days ago" on their command line.
> Sounds like it's time to download some GNU versions ...


date -j -v -30d will do it on FreeBSD...

But the SunOS 5.8 man page for date doesn't show it having that
capability.

Incidentally, http://www.freebsd.org/cgi/man.cgi is kind of neat for
checking man pages across many kinds of Unix systems.

--
Warren Block * Rapid City, South Dakota * USA
Andreas Karrer

2006-12-19, 7:25 pm

* thomasriise <thomasriise@gmail.com>:

> What I need is just variables - date +%Y%m%d - just -n days ago. I
> don't have GNU date.


perl -e '($d,$m,$y)=(localtime(time-30*24*60*60))[3,4,5];printf"%04d%02d%02d",$y+1900,$m+1,$d'


might give a off-by-one result around midnight when DST change occured
in the last 30 days.
thomasriise

2006-12-20, 7:24 am

> PERL -e '($d,$m,$y)=(localtime(time-30*24*60*60))[3,4,5];printf"%04d%02d%02d",$y+1900,$m+1,$d'

- Thanks andrew, your one-liner worked like a charm! In the meantime, I
wrote this little PERL util:

---------------------------------------------
#!/usr/bin/perl
#
#simulate gnu "date --date '1 day ago'
#
#
use Time::Local;
my ($ctime) = time;
$ctime -= 30*24*60*60;
my ($sec,$min,$hour,$mday,$mon,$year,$wday,
$yday,$isdst) =
localtime($ctime);
printf("%04i%02i%02i\n", $year+1900, $mon+1, $mday);
---------------------------------------------

Tintin

2007-01-06, 8:01 pm


"thomasriise" <thomasriise@gmail.com> wrote in message
news:1166612502.164229.240680@t46g2000cwa.googlegroups.com...
>
> - Thanks andrew, your one-liner worked like a charm! In the meantime, I
> wrote this little PERL util:
>
> ---------------------------------------------
> #!/usr/bin/perl
> #
> #simulate gnu "date --date '1 day ago'
> #
> #
> use Time::Local;
> my ($ctime) = time;
> $ctime -= 30*24*60*60;
> my ($sec,$min,$hour,$mday,$mon,$year,$wday,
$yday,$isdst) =
> localtime($ctime);
> printf("%04i%02i%02i\n", $year+1900, $mon+1, $mday);
> ---------------------------------------------


Much easier to do

#!/usr/bin/perl
use POSIX 'strftime';
print strftime "%Y%m%d\n", localtime(time - 24*60*60);



--
Posted via a free Usenet account from http://www.teranews.com

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com