Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function _le {
- local file=$(mktemp)
- # Run the supplied command in screen, and print the exit code on exit
- local screen_cmd='trap '"'"'echo -en "\n"$?'"'"' EXIT; '$@
- screen -Logfile $file -L bash -c "$screen_cmd"
- # Overwrite "screen is terminating" message with empty
- echo -ne '\033[F'
- # echo -n "[screen is terminating]"
- echo -n " "
- # Last line shows the exit code
- local exit_status=$(tail -1 $file | tr -d '[:space:]')
- sed -i '$d' $file
- # Show the log as if it was directly printed to console
- cat $file
- if [ "$exit_status" == "0" ]; then
- # If the command succeeded, remove the log
- rm $file
- else
- mkdir -p $ERRLOGPATH
- local uuid=$(python -c 'import sys,uuid; sys.stdout.write(uuid.uuid4().hex)')
- local cmd=$(echo "$@" | cut -d ' ' -f1 | tr -d '[:space:]')
- local new_file="$ERRLOGPATH/$cmd-$exit_status-$uuid.log"
- mv $file $new_file
- echo "Saved to $new_file"
- fi
- return $exit_status
- }
Add Comment
Please, Sign In to add comment