1

I have two files and I need to change their last modification date: both should be midnight, one on 25th June and the other one on 25th November. Basically, this:

touch -cmt 201606242359.60 summer-file
touch -cmt 201611242359.60 winter-file

Our server timezone is "Europe/Madrid", therefore we enjoy daylight saving time: we are in UTC+1 during the winter and UTC+2 during the summer. Which means that if I run the above commands now, they set the winter-file date correctly, but summer-file is one hour early: 24th June 23:00. If I ran them during the summer, I guess the summer-file would be the one OK and the other one would be 1:00 instead of 0:00.

After a bit of googling and a bit more of trial and error, I came up with this:

TZ=ZZZ-1 touch -cmt 201606242359.60 summer-file
TZ=ZZZ-1 touch -cmt 201611242359.60 winter-file

Which correctly set the date of both files to 0:00 as intended. The problem is... I really don't know what I'm doing here. Changing the timezone to ZZZ-1, because of... magic? Or... is it -1 because we are currently in UTC+1? Next March, when we switch to DST, our server will be 2 hours ahead of UTC instead of 1. Should I use then ZZZ-2 instead, or will ZZZ-1 still be fine? (I'd change the server date and just try myself, but I'm not allowed to do that, it would break a few things).

If I need ZZZ-2 during the summer... is there another expression I can set TZ= to instead, to make my touch work properly all around the year and for any target date? I've tried with GMT, UTC and UTC0, none of them did work (they all set my summer-file to 1:00).

The commands are generated programmatically (in Siebel CRM), I guess I could check the current date and set TZ=ZZZ-1 or TZ=ZZZ-2 as needed (if needed), but I'd rather have only one expression.

Also, please notice our server is running Solaris 10, in case it makes any difference. It usually does...

  • 1
    "both should be midnight": When and where? Do you want "midnight" of your summer file be UTC+2 (= 22:00 UTC) and of your winter file be UTC+1 (= 23:00 UTC)? – ridgy Nov 25 '16 at 13:33
  • You would do best with setting the correct timezone for your file(s), not relative to now. For the winter-file this would be CET (central european time), for the summer-file CEST (central european summer time), see Time Zone Abbreviations. If your "touch" were GNU touch, you could use -d instead of -t to specify the time zone as well (but I don't think this works with Solaris touch). – ridgy Nov 25 '16 at 13:41
  • Thanks @ridgy. Exactly, that's what I need, "local midnight" regardless if "local" means UTC+1 or +2. And no, Solaris touch doesn't have the -d option :(. Not sure about what do you mean with "setting the correct timezone for your files, not relative to now"... with TZ=CET / TZ=CEST? – AJPerez Nov 25 '16 at 13:57
  • 1
    When I issue your original commands (without TZ=) everything works fine, so there seems to be a big difference between Solaris touch and GNU touch. So I cannot test the results, but I think the "correct timezone" would be the one valid for the respective date, so CET for the winter file and CEST for the summer. ZZZ-1 depends on now and so is a "relative" timezone. – ridgy Nov 25 '16 at 14:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.