シェルからapt-getのログ出力

シェルからapt-getのログ出力

私はapt-getgoプログラムでvia execを使用しています。このように:

func aptInstall(pkg, ver string) {
    args := []string{"install", "-y", fmt.Sprintf("%s=%s", pkg, ver)}
    cmd := exec.Command("apt-get", args...)
    cmd.Env = append(os.Environ(), "LANG=en")
    out, err := cmd.CombinedOutput()
    log("apt install", "cmd", fmt.Sprintf("apt-get %s",
        strings.Join(args, " ")), "out", string(out), "err", err)
}

記録されたメッセージには以下が含まれます。

    Selecting previously unselected package nnrforms.
    (Reading database ... 
(Reading database ... 5%
(Reading database ... 10%
(Reading database ... 15%
(Reading database ... 20%
(Reading database ... 25%
(Reading database ... 30%
(Reading database ... 35%
(Reading database ... 40%
(Reading database ... 45%
(Reading database ... 50%
(Reading database ... 55%
(Reading database ... 60%
(Reading database ... 65%
(Reading database ... 70%
(Reading database ... 75%
(Reading database ... 80%
(Reading database ... 85%
(Reading database ... 90%
(Reading database ... 95%
(Reading database ... 100%
(Reading database ... 219690 files and directories currently installed.)
    Preparing to unpack .../nnrforms_531-82a94c0_amd64.deb ...
    Unpacking nnrforms (531-82a94c0) ...
    Setting up nnrforms (531-82a94c0) ...
    [0;1;31mFailed to reload nginx.service: Unit nginx.service not found.[0m

インタラクティブモードで実行されていないことをどのように知り、apt-get進行メッセージを表示しないのですか(Reading database ...ANSI-ESCカラーを追加しないでください)。

修正する

両方の答えを試しましたが、色はセットごとに削除されましたが、TERM=dumb進捗情報はまだ残ります。

- 20230518_144401.646+0800: apt install
  cmd: apt-get install -qqqy -o Dpkg::Progress-Fancy="0" -o APT::Color="0" -o Dpkg::Use-Pty="0" a2up=72-5683a16
  err: <nil>
  out: 
- 20230518_144414.275+0800: apt remove
  cmd: apt-get remove -qqqy -o Dpkg::Progress-Fancy="0" -o APT::Color="0" -o Dpkg::Use-Pty="0" a2s
  err: exit status 100
  out: |
    (Reading database ... 
(Reading database ... 5%
(Reading database ... 10%
(Reading database ... 15%
(Reading database ... 20%
(Reading database ... 25%
(Reading database ... 30%
(Reading database ... 35%
(Reading database ... 40%
(Reading database ... 45%
(Reading database ... 50%
(Reading database ... 55%
(Reading database ... 60%
(Reading database ... 65%
(Reading database ... 70%
(Reading database ... 75%
(Reading database ... 80%
(Reading database ... 85%
(Reading database ... 90%
(Reading database ... 95%
(Reading database ... 100%
(Reading database ... 219699 files and directories currently installed.)
    Removing a2up (72-5683a16) ...
    Failed to disable unit: Unit file a2up.service does not exist.
    dpkg: error processing package a2up (--remove):
     installed a2up package post-removal script subprocess returned error exit status 1
    dpkg: too many errors, stopping
    Errors were encountered while processing:
     a2up
    Processing was halted because there were too many errors.
    E: Sub-process /usr/bin/dpkg returned an error code (1)

-qqqyほとんどの出力メッセージは表示されませんが、apt-get install機能しないようですapt-get remove

ベストアンサー1

-q-qq、を使用して、出力の詳細度を制御し、-qqq警告を抑制できます。2>/dev/null

sudo apt install neofetch -yq -o Dpkg::Progress-Fancy="0" -o APT::Color="0" -o Dpkg::Use-Pty="0" 2> /dev/null

-o Dpkg::Progress-Fancy="0"進行状況バーのキャンセル

-o APT::Color="0"色の使用を無効にする

-o Dpkg::Use-Pty="0"Reading databaseメッセージを隠す

私は走る

sudo apt install neofetch -yq -o Dpkg::Progress-Fancy="0" -o APT::Color="0" -o Dpkg::Use-Pty="0" 2> /dev/null > out

ここに画像の説明を入力してください。

役に立ったことを願って

おすすめ記事