bash: stderr einer Pipe übergeben, stdout in Log

Problem

Manchmal kann es erwünscht sein, die Ausgaben eines Programms in eine Datei zu schreiben, die Fehlerausgaben aber über eine Pipe weiterzufiltern, und dennoch die Ausführung im Hintergrund stattfinden zu lassen.

Lösung

Folgender Codeschnipsel verwendet

  • &1 = stdout
  • &2 = stderr
  • &3 = zusätzlicher Kanal
$ (cmd 3>&1 > ausgabedatei 2>&3 3>&- ) | mail -s "errors aus cmd" &

Weiterlesen

Function csh sh
Send stdout to file prog > file prog > file
Send stderr to file prog 2> file
Send stdout and stderr to file prog >& file prog > file 2>&1
Take stdin from file prog < file prog < file
Send stdout to end of file prog » file prog » file
Send stderr to end of file prog 2» file prog 2» file
Send stdout and stderr to end of file prog »& file prog » file 2>&1
Read stdin from keyboard until c prog «c prog «c
Pipe stdout to prog2 prog | prog2 prog | prog2
Pipe stdout and stderr to prog2 prog |& prog2 prog 2>&1 | prog2

 
wissen/tips_und_tricks/bash/pipe-nur-stderror-einer-pipe-uebergeben-stdout-in-logfile.txt · Zuletzt geändert: 05.09.2010 20:31
 
Recent changes RSS feed Donate Valid XHTML 1.0 Valid CSS Recent cached RSS feed cacert-signed web site: inhalt.serviert.de