amore it !?
per la mia auto, preferisco in un ampio, avendo nel mio .bashrc
una linea come questa:
trap '/usr/games/fortune /usr/share/games/fortunes/bofh-excuses' ERR
(su Debian: apt-get install fortunes-bofh-excuses
:-)
Ma è solo la mia preferenza ;-)
Più seriamente
lastErr() {
local RC=$?
history 1 |
sed '
s/^ *[0-9]\+ *\(\(["'\'']\)\([^\2]*\)\2\|\([^"'\'' ]*\)\) */cmd: \"\3\4\", args: \"/;
s/$/", rc: '"$RC/"
}
trap "lastErr" ERR
Gna
bash: Gna : command not found
cmd: "Gna", args: "", rc: 127
Gna gna
cmd: "Gna", args: "gna", rc: 127
"Gna gna" foo
cmd: "Gna gna", args: "foo", rc: 127
Ebbene, da lì, si potrebbe:
trap "lastErr >>/tmp/myerrors" ERR
"Gna gna" foo
cat /tmp/myerrors
cmd: "Gna gna", args: "foo", rc: 1
O meglio:
lastErr() {
local RC=$?
history 1 |
sed '
s/^ *[0-9]\+ *\(\(["'\'']\)\([^\2]*\)\2\|\([^"'\'' ]*\)\) */cmd: \"\3\4\", args: \"/;
s/$/", rc: '"$RC/
s/^/$(date +"%a %d %b %T ")/"
}
"Gna gna" foo
cat /tmp/myerrors
cmd: "Gna gna", args: "foo", rc: 1
Tue 20 Nov 18:29:18 cmd: "Gna gna", args: "foo", rc: 127
... si potrebbe anche aggiungere altre informazioni come $$, $PPID, $PWD
o forse il tuo ..
Vedere anche [Che cosa fa "set -e" e perché potrebbe essere considerato pericoloso?] (Http://serverfault.com/q/143445/204345) in Errore server. Soprattutto il [bug Debian] (http://www.mail-archive.com/[email protected]/msg473314.html) è piuttosto un trucco per me. – Kontrollfreak