You are not logged in.
Pages: 1
Hey guys,
I'm working on a script that will work something akin to an RSS feed. I have a directory set up and I'm trying to get the bash script to look at the date of the last downloaded (modified) file. Then compare that with today's date. If today's date is "bigger" I want it to wget to the server that stores the podcast that I want to download and see if there's a newer episode available. Probably a very trivial matter, but how can I compare two different dates?
Right now I have the dates in the form of
date +%m%d%y
so basically it looks like
112415
So I end up with two of these values. One for today's current date and one for the last modified file that I want to compare it with. But the problem is I can't do a straight compare. What if one date is..
[[ 112415 -ge 123012 ]]
Clearly this is true, (2015 compared to 2012) but if run with a straight compare it see's that the 11 is smaller than then 12, so it results to false.
What would you guys use if you wish to compare two dates like this? Is there a better format to use that would make this easier?
"I have not failed, I have found 10,000 ways that will not work" -Edison
Offline
Look at `man date` (Examples), and maybe convert your date/times to "seconds since epoch". Then it would be easy to compare them.
Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt «» BunsenLabs on DeviantArt
Offline
right, perhaps a good starting point
http://mywiki.wooledge.org/BashFAQ/102
http://mywiki.wooledge.org/BashFAQ/070
... epoch timestamps. If the epoch is January 1, 1970 at midnight UTC, then it's also called a "Unix timestamp" ...
p.s. for simple comparison y m d (20151230) should also work.
Last edited by brontosaurusrex (2015-11-25 07:05:00)
Offline
y m d (20151230) should also work.
^ This, for any date -- that's why the ISO standard was chosen
Offline
date +%s
is for the timestamp
"Chuck Norris can compile syntax errors."
Offline
Thanks everyone! Hmm so looks like I have some options. I may go for the date +%s Epoch time method and compare the two times that way. Thanks folks! You'll make a shell scripting guru out of me yet...
"I have not failed, I have found 10,000 ways that will not work" -Edison
Offline
Offline
Pages: 1