I have the following entry in cron:

0 0 * * * /path/to/script.sh

in script.sh, there's a call to:

date +%Y%m%d

Even if this executed in zero-time, I'm assuming that the value of date will be for the date after midnight, rather than the date before. Is that correct?

link|improve this question

78% accept rate
feedback

2 Answers

up vote 4 down vote accepted

Yes, you are correct once the clock hits 00:00:00 date = date +1

However, if you really wanted it to be the day before you could do this in your date command:

date "yesterday" +%Y%m%d

link|improve this answer
OK. The script in question moves the current apache log to a file named with that date, then gzip's it. Would make more sense, therefore, for it to use yesterday's date since most of the requests will be from that date. – Bobby Jack Mar 5 '10 at 18:09
3  
@Bobby: Look at logrotate instead of rolling your own: linuxcommand.org/man_pages/logrotate8.html – Zypher Mar 5 '10 at 18:11
feedback

Yes. Computers view 00:00.00 as the start of a new day, so it will be for the date after midnight, not the date before.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.