[solved] Cron in Mint 18.3

Questions about applications and software
Forum rules
Before you post please read how to get help
Post Reply
phil995511
Level 4
Level 4
Posts: 227
Joined: Sat Feb 01, 2014 4:06 am
Location: Geneva

[solved] Cron in Mint 18.3

Post by phil995511 » Sat Dec 02, 2017 10:01 am

Hello,

I realized full install of Mint 18.3 on my workstation it recently.

I place for years a small file (script) that I created in etc / cron.hourly for this OS to update itself alone.

Code: Select all

#!/bin/sh
apt update && apt dist-upgrade -y
This file has root for owner, its access rights are read and write, it is executable.

My problem is that since this install in 18.3, my cron job does not work anymore !

There are many other pre-installed cron jobs like "fstrim" that should not work too... It's very embarrassing for me.

Do you have an idea to solve that ? Does this come from the fact that the root account is locked ?

Best regards.
Last edited by phil995511 on Fri Dec 08, 2017 8:11 am, edited 1 time in total.
Mint 18.3 64 bits Cinnamon

deepakdeshp
Level 10
Level 10
Posts: 3188
Joined: Sun Aug 09, 2015 10:00 am

Re: Cron in Mint 18.3

Post by deepakdeshp » Sat Dec 02, 2017 2:28 pm

In var directory there should be con log which can indicate the problem.
If I have helped you solve a problem, please add [SOLVED] to your first post title, it helps other users looking for help, and keeps the forum clean.
I am using Mint 18.3 Cinnamon 64 bit with AMD processor . Memory 8GB

phil995511
Level 4
Level 4
Posts: 227
Joined: Sat Feb 01, 2014 4:06 am
Location: Geneva

Re: Cron in Mint 18.3

Post by phil995511 » Sat Dec 02, 2017 3:14 pm

Hello Deepakdeshp,

I just find that but nothing more ...

Code: Select all

Dec  2 19:17:01 Station CRON[13481]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Dec  2 19:17:01 Station CRON[13480]: (CRON) info (No MTA installed, discarding output)
Best regards.
Mint 18.3 64 bits Cinnamon

smurphos
Level 4
Level 4
Posts: 494
Joined: Fri Sep 05, 2014 12:18 am

Re: Cron in Mint 18.3

Post by smurphos » Sun Dec 03, 2017 2:04 am

Try running

Code: Select all

run-parts --test /etc/cron.hourly

Does it return the name of your script?

If not does your script have an extension? If so try renaming it. eg rather than foo.sh just foo

What does your root crontab look like?

Code: Select all

sudo crontab -l
Does it include the this command?
01 * * * * root run-parts /etc/cron.hourly

Finally if all else fails add the line directly to the root crontab.

Code: Select all

sudo crontab -e
0 * * * * apt update && apt dist-upgrade -y

phil995511
Level 4
Level 4
Posts: 227
Joined: Sat Feb 01, 2014 4:06 am
Location: Geneva

Re: Cron in Mint 18.3

Post by phil995511 » Mon Dec 04, 2017 5:39 am

Hello Smurphos,


Tks for your reply.


The command "run-parts --test /etc/cron.hourly" display :

Code: Select all

/etc/cron.hourly/apt-update
The name of this file (apt-update) respect the standard format. This script worked perfectly from mint 14 to 18.x but it does not work under Mint 18.3.


The command "sudo crontab -l" display :

Code: Select all

no crontab for root
I have the same message on a version 18.2 where it works


In crontab there is no command below :

01 * * * * root run-parts /etc/cron.hourly

I added it to see if it worked, but it does not work.


Add "0 * * * * apt update && apt dist-upgrade -y" at crontab gives no conclusive result


I think a step in the development of Mint 18.3 or Ubuntu 16.04 was missed. As the /etc folder contains several cron-related subfolders that contain several scripts to run for the proper functioning of the system, I'm afraid that they will not run.


Best regards.
Mint 18.3 64 bits Cinnamon

smurphos
Level 4
Level 4
Posts: 494
Joined: Fri Sep 05, 2014 12:18 am

Re: Cron in Mint 18.3

Post by smurphos » Tue Dec 05, 2017 12:21 pm

Hi,

Sorry the crontab that should contain the commands to run scripts in cron.hourly etc is not the root crontab but the system crontab - my bad.

This is mine in a machine updated to 18.3 - it's the same on a fresh install in virtualbox.

Code: Select all

cat /etc/crontab
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m h dom mon dow user command
17 * * * * root cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
#

Code: Select all

service cron status
is worth checking. Is it running?

Finally I wonder if cron is working fine but

Code: Select all

apt update
is failing for some reason? Have you tried it from a terminal?

phil995511
Level 4
Level 4
Posts: 227
Joined: Sat Feb 01, 2014 4:06 am
Location: Geneva

Re: Cron in Mint 18.3

Post by phil995511 » Tue Dec 05, 2017 2:01 pm

Hello,

When you use a "sudo crontab -e" command it edit a file in /tmp/crontab.OshBIa/crontab

In "etc/crontab" I have the same file than you.


"service cron status" give the answer :

Code: Select all

déc 05 17:17:01 Station CRON[9888]: pam_unix(cron:session): session closed for user root
déc 05 18:00:01 Station CRON[11547]: pam_unix(cron:session): session opened for user root by (uid=0)
déc 05 18:00:01 Station CRON[11548]: (root) CMD (apt update && apt dist-upgrade -y)
déc 05 18:00:07 Station CRON[11547]: (CRON) info (No MTA installed, discarding output)
déc 05 18:00:07 Station CRON[11547]: pam_unix(cron:session): session closed for user root
déc 05 18:17:01 Station CRON[12776]: pam_unix(cron:session): session opened for user root by (uid=0)
déc 05 18:17:01 Station CRON[12777]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
déc 05 18:17:01 Station CRON[12776]: (CRON) info (No MTA installed, discarding output)
déc 05 18:17:01 Station CRON[12776]: pam_unix(cron:session): session closed for user root
déc 05 18:51:01 Station cron[1318]: (root) RELOAD (crontabs/root)
apt work fine. It work perfectly from a terminal.

After an upgrade from my laptop to 18.3 I have a same problem than my workstation...
Mint 18.3 64 bits Cinnamon

phil995511
Level 4
Level 4
Posts: 227
Joined: Sat Feb 01, 2014 4:06 am
Location: Geneva

Re: Cron in Mint 18.3

Post by phil995511 » Tue Dec 05, 2017 2:19 pm

I make a test in "etc/crontab" with :

Code: Select all

0 *     * * *   root    apt update && apt dist-upgrade -y
Mint 18.3 64 bits Cinnamon

phil995511
Level 4
Level 4
Posts: 227
Joined: Sat Feb 01, 2014 4:06 am
Location: Geneva

Re: Cron in Mint 18.3

Post by phil995511 » Tue Dec 05, 2017 5:50 pm

Well, it does not work either ... I'd like to read something like "there is a problem with cron, we will try to fix that" because I'm pretty sure there is a bug in the 18.3 ...
Mint 18.3 64 bits Cinnamon

smurphos
Level 4
Level 4
Posts: 494
Joined: Fri Sep 05, 2014 12:18 am

Re: Cron in Mint 18.3

Post by smurphos » Wed Dec 06, 2017 1:54 am

phil995511 wrote:When you use a "sudo crontab -e" command it edit a file in /tmp/crontab.OshBIa/crontab
That's normal from adding cronjobs via crontab -e or sudo crontab -e

We should tidy this up though. Delete the root crontab we made using

Code: Select all

sudo crontab -r
phil995511 wrote:Hello,
"service cron status" give the answer :

Code: Select all

déc 05 17:17:01 Station CRON[9888]: pam_unix(cron:session): session closed for user root
déc 05 18:00:01 Station CRON[11547]: pam_unix(cron:session): session opened for user root by (uid=0)
déc 05 18:00:01 Station CRON[11548]: (root) CMD (apt update && apt dist-upgrade -y)
déc 05 18:00:07 Station CRON[11547]: (CRON) info (No MTA installed, discarding output)
déc 05 18:00:07 Station CRON[11547]: pam_unix(cron:session): session closed for user root
déc 05 18:17:01 Station CRON[12776]: pam_unix(cron:session): session opened for user root by (uid=0)
déc 05 18:17:01 Station CRON[12777]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
déc 05 18:17:01 Station CRON[12776]: (CRON) info (No MTA installed, discarding output)
déc 05 18:17:01 Station CRON[12776]: pam_unix(cron:session): session closed for user root
déc 05 18:51:01 Station cron[1318]: (root) RELOAD (crontabs/root)
.
OK - the output above indicates cron is working fine.... at 18:00 the root crontab we created ran apt update && apt-dist-upgrade -y and at 18:17 the system crontab run the scripts in cron.hourly.

I've just tested your script in my fresh 18.3 install in virtualbox, put it in /etc/cron.hourly but ran it manually from the terminal this way

Code: Select all

sudo run-parts --report /etc/cron.hourly]
It worked.

One more test - please amend your script in /etc/cron.hourly to write the output to a log file as below. Having done so leave the machine on and check /opt/crontest.txt at some point after 17 minutes past the hour. I'm doing the same.

Code: Select all

#!/bin/sh
apt update  >> /opt/crontest.txt && apt dist-upgrade -y >> /opt/crontest.txt

phil995511
Level 4
Level 4
Posts: 227
Joined: Sat Feb 01, 2014 4:06 am
Location: Geneva

Re: Cron in Mint 18.3

Post by phil995511 » Wed Dec 06, 2017 9:28 am

Hi Smurphos,

As was to be expected

Code: Select all

#!/bin/sh
apt update  >> /opt/crontest.txt && apt dist-upgrade -y >> /opt/crontest.txt
created a file named "crontest.txt" in "/opt" and as was to be expected this file is empty, cron does not work...

Best regards.
Mint 18.3 64 bits Cinnamon

smurphos
Level 4
Level 4
Posts: 494
Joined: Fri Sep 05, 2014 12:18 am

Re: Cron in Mint 18.3

Post by smurphos » Wed Dec 06, 2017 5:26 pm

It looks like something is wrong or has changed with apt. There is nothing wrong with cron as far as I can tell. Other jobs were working on my system.

Change the script to apt-get rather than apt and it works just fine launched by the system crontab.

Code: Select all

#!/bin/sh
apt-get update  >> /opt/crontest.txt && apt-get dist-upgrade -y >> /opt/crontest.txt
Oddly just having this in the root crontab set up via sudo crontab -e does work as done running your script via run-parts as sudo rather than root

Code: Select all

0 * * * * apt update  >> /opt/crontest.txt && apt dist-upgrade -y >> /opt/crontest.txt

Code: Select all

sudo run-parts --report /etc/cron.hourly
Should have asked before but had your original script worked in previous versions of Mint or another distro entirely? A bit of digging and it looks like Mint's 'apt' command is unique to Mint. It's a Python wrapper that gives the Mint apt functionality that is also in apt-get, aptitude, apt-cache, & apt-mark as-well as apt. I wonder if it's check to add sudo to the command doesn't work properly if launched from the system cron?

https://github.com/linuxmint/mintsystem ... al/bin/apt

smurphos
Level 4
Level 4
Posts: 494
Joined: Fri Sep 05, 2014 12:18 am

Re: Cron in Mint 18.3

Post by smurphos » Fri Dec 08, 2017 2:25 am

Another version of the script that does work from /etc/cron.hourly

This specifies the specific path to the system version of apt rather than Mint's Python wrapper version.

Code: Select all

#!/bin/sh
/usr/bin/apt update && /usr/bin/apt dist-upgrade -y

phil995511
Level 4
Level 4
Posts: 227
Joined: Sat Feb 01, 2014 4:06 am
Location: Geneva

Re: Cron in Mint 18.3

Post by phil995511 » Fri Dec 08, 2017 8:10 am

Hello Smurphos,

Thanks for your help. Indeed it appears that APT is involved ...

My script worked long ago with "apt-get" when "apt" did not need the "-get" to work towards the 17.x version of Mint I had transformed.

Maybe it would be nice to report this bug... It is unfortunate that the APT control have been modified by the Mint team and it is the reason of this bug.

If I was developer of Mint, I'll let kernel.org integrate these functions and ensure its proper functioning...

I wish you an excellent end of year festivities.
Mint 18.3 64 bits Cinnamon

smurphos
Level 4
Level 4
Posts: 494
Joined: Fri Sep 05, 2014 12:18 am

Re: [solved] Cron in Mint 18.3

Post by smurphos » Mon Dec 11, 2017 2:33 am

No worries it was interesting to try and troubleshoot. Merry Christmas to you too!

I've done a bit more digging this morning - it looks like the bug was introduced in a commit made in August this year to the Mint version of apt which throws an error if Mint's apt is not run from a terminal environment. I've raised an issue on Github - https://github.com/linuxmint/mintsystem/issues/69

I also worked out why it was working from the root crontab - the root crontab's environment doesn't include /usr/local/bin so the command was defaulting to the debian/system version apt.

The System crontab does specify /usr/local/bin in /etc/crontab so your original script was trying to use Mint's apt.

Mint's apt has actually been around a lot longer than the debian/system version so it's not so much that they have messed with it, just that it is currently broken.

Post Reply

Return to “Software & Applications”