UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old January 16th, 2005, 10:20 PM
izza_azhar izza_azhar is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 49 izza_azhar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 33 m 57 sec
Reputation Power: 4
how to know 3 mont's ago date?

i want to search file that is 3 month's ago according the file name..
file name is such

ATK_7B1_WIP_20041116160700.1.xml.dat
ATK_7B1_WIP_20041116160700.2.xml.dat
ATK_7B1_WIP_20041116160700.3.xml.dat
ATK_7B1_WIP_20041116160700.4.xml.dat
and the proram is like:
#!/bin/bash

is_older()
{
DATE=$(date -u "$1" +%Y-%m-%d)
TODAY=$(date -u "$(date +%Y-%m-%d) $2 $3 $4 $5" +%s)
COMPARE=$(date -u "$DATE" +%s)
test $(($TODAY - $COMPARE)) -le 0 && return 1 || return 0
}

for FILENAME in ATK_*.dat ; do
FILEDATE=$(echo $FILENAME | cut -c 13-20)
if is_older $FILEDATE -3 months ; then
echo "$FILENAME is older than 3 months."
else
echo "$FILENAME is younger than 3 months."
fi
done

but there's an error comparing in is_lder function such:
date: 0551-402 Invalid character in date/time specification
how can i solve this..please

Reply With Quote
  #2  
Old January 18th, 2005, 08:32 AM
zlutovsky zlutovsky is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Prague, Czech Rep.
Posts: 116 zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 22 h 34 sec
Reputation Power: 6
Quote:
Originally Posted by izza_azhar
i want to search file that is 3 month's ago according the file name..
file name is such

ATK_7B1_WIP_20041116160700.1.xml.dat
ATK_7B1_WIP_20041116160700.2.xml.dat
ATK_7B1_WIP_20041116160700.3.xml.dat
ATK_7B1_WIP_20041116160700.4.xml.dat
and the proram is like:
#!/bin/bash

is_older()
{
DATE=$(date -u "$1" +%Y-%m-%d)
TODAY=$(date -u "$(date +%Y-%m-%d) $2 $3 $4 $5" +%s)
COMPARE=$(date -u "$DATE" +%s)
test $(($TODAY - $COMPARE)) -le 0 && return 1 || return 0
}

for FILENAME in ATK_*.dat ; do
FILEDATE=$(echo $FILENAME | cut -c 13-20)
if is_older $FILEDATE -3 months ; then
echo "$FILENAME is older than 3 months."
else
echo "$FILENAME is younger than 3 months."
fi
done

but there's an error comparing in is_lder function such:
date: 0551-402 Invalid character in date/time specification
how can i solve this..please



Read "man date" carefuly. Your line

DATE=$(date -u "$1" +%Y-%m-%d)

is not correct. Put

set -xv

in the beginning of the script and

set -x

as the first command if the function is_older() and run the script again. You will see the intermediate results and can find the errors. If I were you, I would read (and study) some tutorial of the shell programming.

I thing I have solved something similar for you some time ago. Have you tried it?

Regards zlutovsky

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > how to know 3 mont's ago date?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway