1

I have this /etc/cron.d/reboot file:

PROJECT_ROOT=/usr/local/share/applications/ana
NODE_PATH=/usr/bin/node
REBOOT_SCRIPT=/usr/sbin/reboot

SCRIPT=scripts/server-reload-messages.js
0 5 * * * root cd $PROJECT_ROOT && $NODE_PATH $SCRIPT create 
1 5 * * * root $REBOOT_SCRIPT

I need the script to work once a day at 5am, but it works at 5 and 17.


Edit by comments


@roaima, thanks for the advice to look at the cron logs. Now I see that in fact it only works once a day, but then I need to rename the task. The thing is, while i using the application, I got a message that the server will now restart, I checked the date, it was 05:00 PM, I had no doubt that something was going wrong.

May 15 05:00:01 mail CROND[23278]: (root) CMD (cd $PROJECT_ROOT && $NODE_PATH $SCRIPT create )
May 16 05:00:01 mail CROND[52008]: (root) CMD (cd $PROJECT_ROOT && $NODE_PATH $SCRIPT create )
May 17 05:00:01 mail CROND[5363]: (root) CMD (cd $PROJECT_ROOT && $NODE_PATH $SCRIPT create )
May 18 05:00:01 mail CROND[19420]: (root) CMD (cd $PROJECT_ROOT && $NODE_PATH $SCRIPT create )

Here's what I managed to find out, the date format in the system is strange, it looks like this at 19:20:

date
Thu May 18 07:20:02 EDT 2023
kolserdav
  • 111
  • 5
  • 3
    in over 30 years of Unix experience, I've never seen cron use 12 hour time – Jaromanda X May 18 '23 at 09:53
  • 1
    There must be a different reason why these scripts are also run at 17:00. Change the second line to `2 5 * * * root $REBOOT_SCRIPT` and add `1 5 * * * root /usr/bin/logger "This is the 5 am script"`. Examine the logs after the reboot at 17:00. – Ljm Dullaart May 18 '23 at 10:08
  • 1
    I also can't reproduce this. I'm really curious to see the answer, once it's been identified. My own suggestion would be that there's a different cron fragment somewhere that's triggering at 17:01. Anything helpful in the cron log? – roaima May 18 '23 at 10:19
  • Thanks everyone for the replies. I have corrected my question, most likely the problem is caused by the time format on my server. – kolserdav May 18 '23 at 11:27
  • 1
    Is EDT the correct time zone or perhaps one that is 12 hours different from the timezone you are expecting? Because it's 07:45 (am) in EDT right now, so I'm guessing you're not there. – bxm May 18 '23 at 11:44
  • 1
    Maybe your server is hosted in EDT, and you're half a world away... if so, I'd change the timezone to what makes most sense to you and the function the server provides. It's all just a lense over UTC anyway (though not as far as cron is concerned, clearly). – bxm May 18 '23 at 11:51
  • 1
    Compare also [this](https://unix.stackexchange.com/questions/741976/should-i-still-use-utc-for-all-my-servers/741978#741978) (mine) answer to the question *Should I use UTC for all my servers?*. – Marcus Müller May 18 '23 at 14:31
  • @bxm thanks you are right – kolserdav May 19 '23 at 03:18

1 Answers1

0

The correct answer was in the comments from user bxm . The matter is that the time zone of the server for 12 hours differs from the time zone expected by me.

kolserdav
  • 111
  • 5
  • In that case you can explain a cron entry for 5am firing at your 5pm, but it doesn't yet explain how "_it works at 5 and 17_" – roaima May 19 '23 at 06:39
  • I made a mistake when I wrote that it works both at 5 and at 17, I just saw what works at 5 at the very beginning in the logs, and when it worked at 17 I saw it myself, but I didn’t immediately check in the logs this repeated operation in a day or the only one. – kolserdav May 19 '23 at 07:17