MillmoorRon
Posts: 10
Joined: Mon Feb 29, 2016 7:28 pm

Cron running at wrong time

Thu Mar 02, 2017 4:40 pm

I have a cron job:

Code: Select all

00 12 * * * /home/pi/script.sh
which I would expect to run at noon everyday, however it actually runs at 11:00 everyday!

My location and time zone are set using

Code: Select all

raspi-config
The date command returns the correct date, time and timezone (GMT).

Why does it run an hour early and where does cron get the time from?

User avatar
DougieLawson
Posts: 38536
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Cron running at wrong time

Thu Mar 02, 2017 11:07 pm

Have you restarted crond after changing your timezone?
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

I'll do your homework for you for a suitable fee.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

User avatar
Gavinmc42
Posts: 4397
Joined: Wed Aug 28, 2013 3:31 am

Re: Cron running at wrong time

Fri Mar 03, 2017 1:13 am

I had trouble too, google showed one answer that works for me
I put the timezone in the cron script, this will run every minute

* * * * * TZ=EST-10 /home/tc/script.sh
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

MillmoorRon
Posts: 10
Joined: Mon Feb 29, 2016 7:28 pm

Re: Cron running at wrong time

Fri Mar 03, 2017 9:20 am

DougieLawson wrote:Have you restarted crond after changing your timezone?
If I restart the cron service then it runs at the correct time until I reboot, then it goes an hour early again!

It seems that something is changing during boot which affects it.

User avatar
DougieLawson
Posts: 38536
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Cron running at wrong time

Fri Mar 03, 2017 9:31 am

What do you get from a timedatectl command? And where in the World are you - I only need to know your country/nearest big city?
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

I'll do your homework for you for a suitable fee.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

MillmoorRon
Posts: 10
Joined: Mon Feb 29, 2016 7:28 pm

Re: Cron running at wrong time

Fri Mar 03, 2017 9:53 am

DougieLawson wrote:What do you get from a timedatectl command? And where in the World are you - I only need to know your country/nearest big city?
I don't have timedatectl. Which package is this in?

Code: Select all

timedatectl: command not found
I'm in the UK, GMT.

Code: Select all

[email protected] ~ $ date
Fri Mar  3 09:41:06 GMT 2017

User avatar
DougieLawson
Posts: 38536
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Cron running at wrong time

Fri Mar 03, 2017 11:33 am

You're not running Raspbian Jessie. What OS is it?
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

I'll do your homework for you for a suitable fee.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

MillmoorRon
Posts: 10
Joined: Mon Feb 29, 2016 7:28 pm

Re: Cron running at wrong time

Fri Mar 03, 2017 11:40 am

DougieLawson wrote:You're not running Raspbian Jessie. What OS is it?
Debian GNU/Linux 7.11 (wheezy)

User avatar
DougieLawson
Posts: 38536
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Cron running at wrong time

Fri Mar 03, 2017 11:42 am

MillmoorRon wrote:
DougieLawson wrote:You're not running Raspbian Jessie. What OS is it?
Debian GNU/Linux 7.11 (wheezy)
Why are you running that unsupported stuff? Upgrade to Jessie 2017-02-16 and retest.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

I'll do your homework for you for a suitable fee.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

MillmoorRon
Posts: 10
Joined: Mon Feb 29, 2016 7:28 pm

Re: Cron running at wrong time

Fri Mar 03, 2017 1:17 pm

DougieLawson wrote:Why are you running that unsupported stuff? Upgrade to Jessie 2017-02-16 and retest.
Why am I running it? Because that was the latest version when I installed it and I have subsequently spent MANY hours getting things (hardware and software) working properly on it.
https://www.raspberrypi.org/blog/raspbian-jessie-is-here/ wrote:Starting with a clean image is the recommended way to move to Jessie. If you really need to update a Wheezy image, we have tried an unsupported upgrade path which is documented on the forums
Doesn't sound like an "upgrade" to me! Sounds like a recipe for many more problems that I won't be able to get support for either.

If I have to start from a new image and then reinstall/configure all the packages and settings again then it's not worth the effort.

If I ever find the time to do this I'll give it a go, but I suppose I'll just have to set my cron jobs an hour later for now!

User avatar
jojopi
Posts: 3193
Joined: Tue Oct 11, 2011 8:38 pm

Re: Cron running at wrong time

Fri Mar 03, 2017 2:10 pm

How are you determining that the jobs run an hour early? Do you notice them starting, and if so are they exactly one hour off, or just approximately? Or do you check some log files later to find out what time the jobs ran; which files and what do they say?

Are you sure that you have only set the system timezone using raspi-config, and not any individual TZ= overrides anywhere? Have you have ever used a timezone that was offset from UTC in winter? UTC is the default, and British time is currently the same.

MillmoorRon
Posts: 10
Joined: Mon Feb 29, 2016 7:28 pm

Re: Cron running at wrong time

Fri Mar 03, 2017 2:17 pm

How are you determining that the jobs run an hour early? Do you notice them starting, and if so are they exactly one hour off, or just approximately? Or do you check some log files later to find out what time the jobs ran; which files and what do they say?
I intially noticed accidentally but when I checked more closely I found that all jobs are running exactly 1 hour early.
Are you sure that you have only set the system timezone using raspi-config, and not any individual TZ= overrides anywhere?
Not that I know of. Where would I look for such overrides?
Have you have ever used a timezone that was offset from UTC in winter? UTC is the default, and British time is currently the same.
I set the location and time zone at installation and never thought to look again as the date and time are always correct. We move to BST during summer but again the system takes care of this - or so I thought!

MillmoorRon
Posts: 10
Joined: Mon Feb 29, 2016 7:28 pm

Re: Cron running at wrong time

Mon Mar 06, 2017 12:05 pm

As a demonstration, time zone set using raspi-config:

Code: Select all

[email protected] ~ $ sudo raspi-config

Current default time zone: 'Europe/London'
Local time is now:      Mon Mar  6 11:54:24 GMT 2017.
Universal Time is now:  Mon Mar  6 11:54:24 UTC 2017.
These lines in crontab:

Code: Select all

53 12 * * * date >> /home/pi/dates.txt
52 11 * * * date >> /home/pi/dates.txt
Output at 11:53:

Code: Select all

[email protected] ~ $ cat dates.txt
Mon Mar  6 11:53:01 GMT 2017
There was no TZ= line in my .profile but I tried added one to check and it made no difference.

User avatar
jojopi
Posts: 3193
Joined: Tue Oct 11, 2011 8:38 pm

Re: Cron running at wrong time

Mon Mar 06, 2017 4:16 pm

Does this command show that the cron daemon has its own TZ setting, one hour ahead of GMT?

Code: Select all

sudo cat /proc/$(pidof cron)/environ |tr '\0' '\n'

MillmoorRon
Posts: 10
Joined: Mon Feb 29, 2016 7:28 pm

Re: Cron running at wrong time

Mon Mar 06, 2017 4:22 pm

This is my output:

Code: Select all

[email protected] ~ $ sudo cat /proc/$(pidof cron)/environ |tr '\0' '\n'
CONSOLE=/dev/console
HOME=/
runlevel=2
INIT_VERSION=sysvinit-2.88
TERM=linux
COLUMNS=228
PATH=/bin:/usr/bin:/sbin:/usr/sbin
RUNLEVEL=2
PREVLEVEL=N
LANG=en_GB.UTF-8
SHELL=/bin/sh
PWD=/
previous=N
LINES=64

MillmoorRon
Posts: 10
Joined: Mon Feb 29, 2016 7:28 pm

Re: Cron running at wrong time

Wed Mar 29, 2017 11:45 am

Now that we are on BST cron runs at the correct time!

Return to “Raspberry Pi OS”