Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

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

share|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

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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