我有一个由 cron 触发的自动安装 bash 脚本,当满足某些条件时,会触发安装过程。它本质上看起来像这样:
#!/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
上面的脚本旨在dstat
如果发现未安装则进行安装。如果我手动运行此脚本,一切都会按预期进行。输出看起来/tmp/dstat.log
像:
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
就安装成功了。现在我在 crontab 中添加一个新条目并让该脚本定期运行。我发现dstat
没有安装,输出如下:
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.
我真的很困惑。