log-in-datei-schreiben
Problem
Für Dokumentationszwecke ist oftmals sehr nützlich, wenn nicht nur die Kommandoausgabe in einer Logdatei mitprotokolliert wird, sondern auch der Aufruf über das Kommando selbst. Dazu benutzt an sinnvollerweise das set
Kommando im Zusammenspiel mit einer Ausgabeumleitung.
Lösung
Hier im Beispiel soll die Ausgabe zweier Kommandos (uptime
und lsusb
) in der Logdatei out.log
protokolliert werden. Der Ausdruck mit set
muss geklammert werden.
$ (set -x; uptime; lsusb) >out.log 2>&1
Den Kommandos in der Logdatei ist jeweils ein Pluszeichen vorangestellt, danach folgt die Ausgabe.
$ cat out.log + uptime 19:31:10 up 7:37, 3 users, load average: 0,89, 0,42, 0,28 + lsusb Bus 004 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub Bus 004 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 003 Device 003: ID 060b:2401 Solid Year Bus 003 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 002 Device 002: ID 2109:0810 Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub Bus 001 Device 005: ID 046d:082c Logitech, Inc. Bus 001 Device 004: ID 2109:0810 Bus 001 Device 003: ID 1a7c:0192 Evoluent Bus 001 Device 008: ID 046d:c521 Logitech, Inc. Cordless Mouse Receiver Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
log-in-datei-schreiben.txt · Zuletzt geändert: 2020/01/23 17:37 von 127.0.0.1