nixCraft Linux Forum

nixCraft

Linux Tech Support Forum

How to calculate date minus 72 hours?

This is a discussion on How to calculate date minus 72 hours? within the Shell scripting forums, part of the Development/Scripting category; There are some log files on my server (CentOS), filenames are like this: 20070929210001.srv0912.tgz I need to find logfiles between ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Register FAQ Members List Calendar Forgotten your password? Mark Forums Read
  #1 (permalink)  
Old 10-09-2007, 09:42 PM
Junior Member
User
 
Join Date: Oct 2007
My distro: Ubuntu
Posts: 2
Rep Power: 0
svinopas is on a distinguished road
Default How to calculate date minus 72 hours?

There are some log files on my server (CentOS), filenames are like this: 20070929210001.srv0912.tgz

I need to find logfiles between -72 and -2 hours from current date (time). Is it possible to do it with some UNIX commands and implement in shell script then?

Last edited by svinopas; 10-09-2007 at 09:57 PM.. Reason: added OS
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 10-09-2007, 10:37 PM
Junior Member
User
 
Join Date: Oct 2007
My distro: Ubuntu
Posts: 2
Rep Power: 0
svinopas is on a distinguished road
Default

I have found how to do this:
Code:
DATE_NOW_UNIXTIME=`date --date=now +"%s"`
LOG_HOURS=75
unixtime_LOG_HOURS=`expr $LOG_HOURS \* 60 \* 60`
echo `expr $DATE_NOW_UNIXTIME - $unixtime_LOG_HOURS`
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads

Thread Thread Starter Forum Replies Last Post
Shell date command for manipulation and formatting date newbie4 Shell scripting 4 10-28-2008 08:33 PM
script to ping + date dendi_rm Shell scripting 3 09-11-2007 11:42 AM
How can I rename a file by its date? warren Linux software 5 03-30-2006 01:11 PM


All times are GMT +5.5. The time now is 07:36 PM.


Powered by vBulletin® Version 3.7.4 - Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36