Meldung bei stderr Ausgabe?
Pierre Bernhardt
pierre at starcumulus.owl.de
Fri Mar 23 02:09:26 CET 2012
Am 24.08.2011 21:40, schrieb Frank Bergmann:
Hallo All die mir geholfen haben. Hier mal ein Stück Script welches
aus Euren Tipps entstanden ist und ich Euch nicht vorenthalten wollte:
# Start the background process
# Open an own fd nr. 3
exec 3<&1
{
{
# Add an short sleep so an PIG for CMD_PID has to been generated
# correctly. This should prevent the ps -p without executing with an
# pid argument in watchloop.
${SLEEP_EXE} 1
# The stdout of cmd is redirected to 3 and stderr to 1. So now all
# trailing unix cmd can now work with "stderr". Now duplicated these
# stdout by tee and write the copy to stderr which is solved by
writing
# to /dev/stderr.
{
${COMMAND2EXECUTE}
} 2>&1 >&3|\
${TEE_EXE} /dev/stderr|\
{
while ${READ_EXE} STDLINES
do
ALLSTD=${ALLSTD:-}${STDLINES}
done
# if there is content in "stderr of cmd" is found and watch
stderr
# is enabled, then exit the process chain with exit code 254.
[[ -n "${ALLSTD:-}" && "${STDERRFAILURE}" = 'yes' ]] &&\
exit 254
# otherwise exit with exit code 0
exit 0
}
# Save pipestatus array (0 is executed command, 1 is tee and 2
# is from check subshell)
EXITCODES=(${PIPESTATUS[*]})
# If cmd exit code is ok than exit with the exit code of the watch
stderr
# process chain.
[[ ${EXITCODES[0]} -eq 0 ]] &&\
exit ${EXITCODES[2]}
# otherwise exit with the exicode of the executed command
exit ${EXITCODES[0]}
} 3>&1
} &
CMD_PID=${!}
Dahinter läuft noch eine Schleife welche eine Zeit lang auf das
Ende von $CMD_PID wartet und wenn das nicht "rechtzeitig" der Fall
ist wird die gesamte Prozesskette vom "letzten" Prozess an abgeschossen.
Das Konstrukt sorgt auf jeden Fall dafür, das stderr und stdout schön
nach Außen auf den aufrufenden Prozess durchgereicht wird aber trotzdem
erkannt wird, wenn was auf stderr raus geschrieben wird, und alles
ohne temporäre Dateien :-)
Bitte verzeiht, wenn ich die Variablen nicht weiter erkläre. Ich denke
Sie sind größtenteils selbsterklärt
Und irgendwann gieße ich das in Python ;-)
MfG...
Pierre
More information about the Linux
mailing list