1

Yes, I'm aware of unattended-upgrade, but I don't like that package's limitations. I've got a PHP script that makes the following calls:

...
system("/usr/bin/apt-get update");
system("/usr/bin/apt-get -y upgrade 2>&1 > /tmp/apt_get.txt");
system("/usr/bin/apt-get autoremove");
system("/usr/bin/apt-get autoclean");
...

The script is set up via cron to run automatically on a schedule. It appears to execute all of the commands correctly as root. However, 'apt-get -y upgrade' doesn't actually perform the upgrade as evidenced here in the output of /tmp/apt_get.txt:

Reading package lists...
Building dependency tree...
Reading state information...
The following packages will be upgraded:
  iproute
1 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 444 kB of archives.
After this operation, 1,024 B of additional disk space will be used.
Get:1 http://us.archive.ubuntu.com/ubuntu/ precise-updates/main iproute amd64 20111117-1ubuntu2.3 [444 kB] Fetched 444 kB in 1s (374 kB/s)

Manually running 'apt-get upgrade' shows that the package was downloaded but not installed:

Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be upgraded:
  iproute
1 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/444 kB of archives.
After this operation, 1,024 B of additional disk space will be used.
Do you want to continue [Y/n]? n
Abort.

So apt-get successfully downloads the package but doesn't actually perform the upgrade. What do I need to change to get this script to work as expected? It almost seems like a bug in "apt-get -y upgrade" itself. (Running Ubuntu 12.04.4 LTS here.)

2

I assume it asks whether to overwrite/keep/diff edited configuration files. You need to add DEBIAN_FRONTEND=noninteractive in this case.

DEBIAN_FRONTEND=noninteractive apt-get -y upgrade
  • Running 'sudo apt-get upgrade' manually (from Bash) didn't ask that for the 'iproute' package. – Su Do Jun 3 '14 at 19:31
  • Please change the redirection in your code to: >/tmp/apt_get.txt 2>&1, ordering is important here. And then add the last lines from /tmp/apt_get.txt again. – user70408 Jun 4 '14 at 9:26
  • Make the change. Now the output shows that PATH is not defined. Added some code to compensate. I will see if that works. – Su Do Jun 5 '14 at 16:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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