0

I've encountered problems when I played with system updates automation based on calling apt-get update and apt-get upgrade from crontab. I added two following lines to my crontab file:

10 * * * * apt-get update > /home/log/apt.update
12 * * * * apt-get -y upgrade > /home/log/apt.upgrade

However, the success is quite limited: update process looks ok, but apt-get upgrade throws some kind of errors:

Reading package lists...
Building dependency tree...
Reading state information...
Calculating upgrade...
The following packages were automatically installed and are no longer required:
  linux-headers-4.15.0-65 linux-headers-4.15.0-65-generic
  linux-image-4.15.0-65-generic linux-modules-4.15.0-65-generic
  linux-modules-extra-4.15.0-65-generic
Use 'apt autoremove' to remove them.
The following packages have been kept back:
  linux-generic linux-headers-generic linux-image-generic
The following packages will be upgraded:
  dotnet-host git git-man grub-common grub-pc grub-pc-bin grub2-common
  intel-microcode libpcap0.8 libsqlite3-0 linux-firmware unattended-upgrades
12 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.
Need to get 0 B/86.3 MB of archives.
After this operation, 8,474 kB of additional disk space will be used.
dpkg: warning: 'ldconfig' not found in PATH or not executable
dpkg: warning: 'start-stop-daemon' not found in PATH or not executable
dpkg: error: 2 expected programs not found in PATH or not executable
Note: root's PATH should usually contain /usr/local/sbin, /usr/sbin and /sbin

I belive that the last 4 lines describes problem, but still I have not idea how to fix it. I could'n replicate this behavior trying: - sudo apt-get -y upgrade - works perfectly - sudo -i then su and then apt-get upgrade - also works

I will be than grateful for any hint.

System version: Ubuntu 18.04.3 LTS (GNU/Linux 4.15.0-70-generic x86_64)

Radek
  • 101
  • 2
  • 5
    Is there any reason you're not using [unattended-upgrades](https://askubuntu.com/questions/9/how-do-i-enable-automatic-updates)? That's generally better than trying to roll your own. – vidarlo Dec 11 '19 at 13:04
  • 1
    You also don't need to redirect output. See /var/log/apt/term.log – user535733 Dec 11 '19 at 13:09
  • 2
    The default `PATH` for processes started from root's crontab is very limited (`PATH=/usr/bin:/bin`) - as you can verify for example by adding a simple cron job like `/usr/bin/printenv > /tmp/cronenv` – steeldriver Dec 11 '19 at 13:12
  • 1
    ... see this related question [Crontab execution of multiple commands but last command is omitted](https://askubuntu.com/a/936165/178692) – steeldriver Dec 11 '19 at 13:14
  • Thanks to all of you for explanations :) Now I understand what going on. And I'll give another chance to unattendet-uprgades. Explanations from linked topics was very helpful. Once again thanks to all of you! – Radek Dec 11 '19 at 22:33

0 Answers0