You are not logged in.

#1 2008-10-14 18:48:56

vytalelementz
Member
From: West Palm Beach, FL, USA
Registered: 2007-04-23
Posts: 99

Comparing timestamp of file to a certain time frame

This might be a simple task but I am having trouble trying to write a bash script that takes the timestamp of a file and compares it to a certain time frame. For example, I would like to copy over a file to a certain directory that has a time stamp of between 1pm (13:00) to let's say 3pm (15:00). Any help is appreciated.

Last edited by vytalelementz (2008-10-14 18:52:15)


Best Regards,

The Vytalone

Offline

#2 2008-10-14 19:14:37

vytalelementz
Member
From: West Palm Beach, FL, USA
Registered: 2007-04-23
Posts: 99

Re: Comparing timestamp of file to a certain time frame

FYI: a thorough script is unnecessary. I just need to know how I would compare something like 2:30pm (14:30) to the time frame specified in the last post.

Last edited by vytalelementz (2008-10-14 19:15:19)


Best Regards,

The Vytalone

Offline

#3 2008-10-14 21:24:48

Profjim
Member
From: NYC
Registered: 2008-03-24
Posts: 658

Re: Comparing timestamp of file to a certain time frame

Do you mean 1pm to 3pm on a specific day? Or do you mean you want to match files whose timestamp is between 1pm and 3pm on any day?

If the first, then just do:

timestamp=$(stat --format='%X' $file)
if [[ "$timestamp" -ge xxx && "$timestamp" -le yyy ]]; then
    ...
fi

You'll need to figure out the xxx and yyy for your desired block of time. If on the other hand you want any files last modified between 1pm and 3pm of any day at all, then I think you'll need to retrieve the timestamp in seconds, then mod it by the number of seconds in a day, then compare the result to your desired start time and end time, expressed in seconds since midnight:

timestamp=$(stat --format='%X' $file)
timestamp=$((timestamp % (60*60*24) ))
if [[ "$timestamp" -ge zzz && "$timestamp" -le www ]]; then
    ...
fi

Offline

#4 2008-10-15 02:30:52

vytalelementz
Member
From: West Palm Beach, FL, USA
Registered: 2007-04-23
Posts: 99

Re: Comparing timestamp of file to a certain time frame

Thanks for the reply. I will try your suggestions out to see which works best.


Best Regards,

The Vytalone

Offline

Board footer

Powered by FluxBB