0

No matter what I try seems nothing works to run apt-get command to remove a package (nginx, in this case) then install a package (nginx-extras) with a few updates and finish with upgrade.

I know people will say "it's dangerous" but these are my servers I'm trying to run this across many of my own servers same time. Why won't work?

Will not work, nothing shows up in syslog (but cron job fires correctly).

And already tried add --force-yes but doesn't help...

Below commands are in a file like "my-shell-script" that's called hourly in root crontab:

DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical /usr/bin/apt-get -q --yes -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" remove nginx
DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical /usr/bin/apt-get -q --yes -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" update
DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical /usr/bin/apt-get -q --yes -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" add-apt-repository ppa:nginx/development
DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical /usr/bin/apt-get -q --yes -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" update
DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical /usr/bin/apt-get -q --yes -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" install nginx-extras
DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical /usr/bin/apt-get -q --yes -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" update
DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' /usr/bin/apt-get -q --yes -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade

UPDATE: not sure but I think I found correct crontab log after pipe to syslog:

Reading package lists...
Building dependency tree...
Reading state information...
The following packages will be REMOVED:
  nginx
0 upgraded, 0 newly installed, 1 to remove and 3 not upgraded.
After this operation, 35.8 kB disk space will be freed.
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
E: Sub-process /usr/bin/dpkg returned an error code (2)
Hit:1 http://archive.ubuntu.com/ubuntu xenial InRelease
Get:2 http://security.ubuntu.com/ubuntu xenial-security InRelease [102 kB]
Get:3 http://archive.ubuntu.com/ubuntu xenial-updates InRelease [102 kB]
Hit:4 http://ppa.launchpad.net/nginx/development/ubuntu xenial InRelease
Get:5 http://archive.ubuntu.com/ubuntu xenial-backports InRelease [102 kB]
Fetched 306 kB in 1s (255 kB/s)
Reading package lists...
E: Command line option --yes is not understood in combination with the other options
Hit:1 http://archive.ubuntu.com/ubuntu xenial InRelease
Get:2 http://security.ubuntu.com/ubuntu xenial-security InRelease [102 kB]
Hit:3 http://ppa.launchpad.net/nginx/development/ubuntu xenial InRelease
Get:4 http://archive.ubuntu.com/ubuntu xenial-updates InRelease [102 kB]
Get:5 http://archive.ubuntu.com/ubuntu xenial-backports InRelease [102 kB]
Fetched 306 kB in 1s (200 kB/s)
Reading package lists...
Reading package lists...
Building dependency tree...
Reading state information...
The following additional packages will be installed:
  libhiredis0.13 libluajit-5.1-2 libluajit-5.1-common
  libnginx-mod-http-cache-purge libnginx-mod-http-fancyindex
  libnginx-mod-http-headers-more-filter libnginx-mod-http-lua
  libnginx-mod-http-ndk libnginx-mod-http-perl
  libnginx-mod-http-uploadprogress libnginx-mod-nchan
Suggested packages:
  nginx-doc
The following packages will be REMOVED:
  nginx-full
The following NEW packages will be installed:
  libhiredis0.13 libluajit-5.1-2 libluajit-5.1-common
  libnginx-mod-http-cache-purge libnginx-mod-http-fancyindex
  libnginx-mod-http-headers-more-filter libnginx-mod-http-lua
  libnginx-mod-http-ndk libnginx-mod-http-perl
  libnginx-mod-http-uploadprogress libnginx-mod-nchan nginx-extras
0 upgraded, 12 newly installed, 1 to remove and 3 not upgraded.
Need to get 0 B/1,228 kB of archives.
After this operation, 2,141 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
E: Sub-process /usr/bin/dpkg returned an error code (2)
Hit:1 http://ppa.launchpad.net/nginx/development/ubuntu xenial InRelease
Hit:2 http://archive.ubuntu.com/ubuntu xenial InRelease
Get:3 http://security.ubuntu.com/ubuntu xenial-security InRelease [102 kB]
Get:4 http://archive.ubuntu.com/ubuntu xenial-updates InRelease [102 kB]
Get:5 http://archive.ubuntu.com/ubuntu xenial-backports InRelease [102 kB]
Fetched 306 kB in 1s (267 kB/s)
Reading package lists...
Reading package lists...
Building dependency tree...
Reading state information...
Calculating upgrade...
The following packages have been kept back:
  linux-generic linux-headers-generic linux-image-generic
0 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.
  • Why do you want to run a job that is a one-time thing from cron (hourly)? – Soren A Jul 21 '17 at 11:16
  • 1
    And what errors do you get ? – Soren A Jul 21 '17 at 11:16
  • @SorenA Hourly just cuz I edit it whenever need to run some tasks... it syncs across all my servers by wget so I delete task after finished... I don't see errors anywhere, where will that be? thanks – happyfrog Jul 21 '17 at 11:18
  • 1
    Output from commands run in cron is usually mailed to the user they are run by ... use mailx in terminal to read these mails. – Soren A Jul 21 '17 at 11:22
  • thanks I updated w/ correct cron job output from syslog I believe – happyfrog Jul 21 '17 at 11:42
0

Thanks to @steeldriver for pointing in the right direction. My script just needed the PATH defined on every command, not only upgrade command (was only on the last line initially).

This is now confirmed working automatically and yah nearly every problem I've had with cron jobs is cuz of paths or relative paths. Thanks!

DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' /usr/bin/apt-get -q --yes -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" remove nginx
DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' /usr/bin/apt-get -q --yes -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" update
DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' /usr/bin/apt-get -q --yes -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" add-apt-repository ppa:nginx/development
DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' /usr/bin/apt-get -q --yes -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" update
DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' /usr/bin/apt-get -q --yes -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" install nginx-extras
DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' /usr/bin/apt-get -q --yes -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" update
DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' /usr/bin/apt-get -q --yes -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade

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.