AJ Dhaliwal asked:
Running the following commands on the command line works fine
$sudo apt-get update $sudo apt-get upgrade Reading package lists... Done Building dependency tree Reading state information... Done The following packages will be upgraded: linux-libc-dev 1 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. Need to get 0B/864kB of archives. After this operation, 0B of additional disk space will be used. Do you want to continue [Y/n]?
But running this script using cron…
#!/bin/bash source /home/adm/.profile apt-get update >> /home/adm/update_detailed.log apt-get --yes upgrade >> /home/adm/update_detailed.log echo "Update_successful $(date)" >> /home/adm/update.log
produces the following output:
Reading package lists... Building dependency tree... Reading state information... The following packages will be upgraded: linux-libc-dev 1 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. Need to get 0B/864kB of archives. After this operation, 0B of additional disk space will be used.
Why is the linux-libc-dev package not installed from the bash script but can be installed from the command line? Note that the script is set to run as the superuser.
The script was verified against  and online sources.
Questions I have read on serverfault have mentioned unattended upgrades but I want to understand this issue not use an alternative.
In  I have read that this sort of issue might be caused by the environment variables. This is why I have added the source /home/adm/.profile line to the script. It has not made a difference.
You aren’t the first one to run into this problem and find that it’s pretty much unworkable. That’s why Debian has had a package for this purpose for many years now. It’s named
Install this package, and then configure it by editing the configuration file in the
/etc/cron-apt directory. The default configuration file is very well documented and all the options should be fairly well explained.
Note well, that while you can configure it to automatically update the system, you probably should not, as it will eventually break something important. Better to just set it up to email you when updates are available.
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.