Guest User

Untitled

a guest
Aug 16th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. function _le {
  2. local file=$(mktemp)
  3.  
  4. # Run the supplied command in screen, and print the exit code on exit
  5. local screen_cmd='trap '"'"'echo -en "\n"$?'"'"' EXIT; '$@
  6. screen -Logfile $file -L bash -c "$screen_cmd"
  7.  
  8. # Overwrite "screen is terminating" message with empty
  9. echo -ne '\033[F'
  10. # echo -n "[screen is terminating]"
  11. echo -n " "
  12.  
  13. # Last line shows the exit code
  14. local exit_status=$(tail -1 $file | tr -d '[:space:]')
  15. sed -i '$d' $file
  16.  
  17. # Show the log as if it was directly printed to console
  18. cat $file
  19.  
  20. if [ "$exit_status" == "0" ]; then
  21. # If the command succeeded, remove the log
  22. rm $file
  23. else
  24. mkdir -p $ERRLOGPATH
  25. local uuid=$(python -c 'import sys,uuid; sys.stdout.write(uuid.uuid4().hex)')
  26. local cmd=$(echo "$@" | cut -d ' ' -f1 | tr -d '[:space:]')
  27. local new_file="$ERRLOGPATH/$cmd-$exit_status-$uuid.log"
  28. mv $file $new_file
  29. echo "Saved to $new_file"
  30. fi
  31. return $exit_status
  32. }
Add Comment
Please, Sign In to add comment