ユーザー操作なしでUbuntuパッケージとカーネルをアップグレードする

ユーザー操作なしでUbuntuパッケージとカーネルをアップグレードする
#!/bin/bash

### change from Static IP to DHCP
H=$(date +%H)
if (( 11 <= 10#$H && 10#$H < 18 )); then
echo -e  "network:\n  version: 2\n  renderer: NetworkManager\n  ethernets:\n   enp0s3:\n    dhcp4: yes" > /etc/netplan/01-network-manager-all.yaml
sudo netplan apply

### create the log file 
var=$(ip a | grep -A 3 ens33 | grep "inet " | cut -d " " -f 6) 
echo DHCP IP= $var > logfile
echo ########################################

### update and upgrade packages without user interaction
sudo apt-get update && apt-get --yes --force-yes upgrade > tmp.txt

### add the lists to the log file
echo "packages that were updated" >> logfile
awk '/^the following/{p=0} /NEW packages will be installed/{p=1} p' tmp.txt >> logfile
echo ########################################
echo "packages being cleaned" >> logfile
awk '/^the following/{p=0} /packages were automatically installed and are no longer required/{p=1} p' tmp.txt >> logfile
echo ########################################
### remove the not required packages
sudo apt autoremove

### chcek if reboot needed or not
cat tmp.txt | grep -A 20 "the following NEW packages will be installed:" |grep "grub-common-*" > tmp2.txt
cat tmp.txt | grep -A 20 "the following NEW packages will be installed:" |grep "grub-pc-*" >> tmp2.txt
cat tmp.txt | grep -A 20 "the following NEW packages will be installed:" |grep "linx-image-*" >> tmp2.txt
cat tmp.txt | grep -A 20 "the following NEW packages will be installed:" |grep "linux-headers-*" >> tmp2.txt

if [ -s tmp2.txt ]
then
    echo "there's kernel/grub update happened" >> logfile
    echo ########################################
    reboot
else
    echo "there's no kernel/grub update happened" >> logfile
    echo ########################################
fi

### clean the tmp file
rm -f tmp.txt tmp2.txt
 
### last reboot time
uptime=$(uptime -s)
echo last reboot time= $uptime >> logfile
echo ########################################
fi

### back IP again to Static
echo -e  "network:\n  version: 2\n  renderer: NetworkManager\n  ethernets:\n   enp0s3:\n    addresses:\n     - 192.168.100.100/24" > /etc/netplan/01-network-manager-all.yaml
sudo netplan apply

これは私が試したコードですが、出力が正しくなく、私の問題がどこにあるのかわかりません。

ベストアンサー1

スクリプトにタイプミスがあります。 aptの出力で大文字Tで始まり、「次へ...」を作成します。で見た別のスペルミスgrep linx-imageapt list --upgradableお使いのシステムでその機能が利用可能であることを確認してください。私はインタラクティブなコマンドではないので、出力に触れないと仮定します。

おすすめ記事