0

I have an auto install bash script triggered by cron, when some condition is met, the install process is triggered. It essentially looks like this:

#!/bin/bash

if [[ -f "/usr/bin/apt-get" ]]; then
    if [[ ! -f "/usr/bin/dstat"  ]]; then
        apt-get update && apt-get install -y dstat > /tmp/dstat.log
    fi
fi

The script above is intended to install dstat if it is found not installed. If I manually run this script, everything works as expected. The output looks in /tmp/dstat.log like:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
  dstat
0 upgraded, 1 newly installed, 0 to remove and 13 not upgraded.
Need to get 0 B/68.2 kB of archives.
After this operation, 351 kB of additional disk space will be used.
Selecting previously unselected package dstat.
(Reading database ... 33233 files and directories currently installed.)
Preparing to unpack .../dstat_0.7.2-3build1_all.deb ...
Unpacking dstat (0.7.2-3build1) ...
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
Setting up dstat (0.7.2-3build1) ...

dstat is installed successfully. Now I add a new entry in crontab and let this script run periodically. I found dstat is not installed, the output looks like:

Reading package lists...
Building dependency tree...
Reading state information...
The following NEW packages will be installed:
  dstat
0 upgraded, 1 newly installed, 0 to remove and 13 not upgraded.
Need to get 0 B/68.2 kB of archives.
After this operation, 351 kB of additional disk space will be used.

I'm really confused.

  • Did you purge it before ry-trying with cron? – Jan Dec 18 '15 at 10:41
  • No I didn't. I will try it now. But why does purge matter? – Elgs Qian Chen Dec 18 '15 at 10:42
  • I ran apt-get purge dstat, but the next run of the cron still did not install dstat. – Elgs Qian Chen Dec 18 '15 at 10:46
  • I tested it with jq again, it also does not work. Sorry in my original post I said jq worked while dstat did not, which was a wrong statement. I have fixed in the original post. – Elgs Qian Chen Dec 18 '15 at 11:12
  • Try with -y but be careful... – Jan Dec 18 '15 at 12:01

Your Answer

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

Browse other questions tagged or ask your own question.