Guest User

Untitled

a guest
Oct 18th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. function surpress { /bin/rm --force /tmp/surpress.out 2> /dev/null; ${1+"$@"} > /tmp/surpress.out 2>&1 || cat /tmp/surpress.out; /bin/rm /tmp/surpress.out; }
  2.  
  3. surpress foo -a bar
  4.  
  5. OUTPUT=`tempfile`
  6. program_we_want_to_capture &2>1 > $OUTPUT
  7. [ $? -ne 0 ]; then
  8. cat $OUTPUT
  9. exit 1
  10. fi
  11. rm $OUTPUT
  12.  
  13. #!/bin/bash
  14.  
  15. the_command 2>&1 | awk '
  16. BEGIN
  17. {
  18. # Initialize our error-detection flag.
  19. ErrorDetected = 0
  20. }
  21. # Following are regex that will simply skip all lines
  22. # which are good and we never want to see
  23. / Added UserList source/ ||
  24. / Added User/ ||
  25. / init domainlist / ||
  26. / init iplist / ||
  27. / init urllist / ||
  28. / loading dbfile / ||
  29. /^$/ {next} # Uninteresting message. Skip it.
  30.  
  31. # Following are lines that we good and we always want to see
  32. / INFO: ready for requests /
  33. {
  34. print " " $0 # Expected message we want to see.
  35. next
  36. }
  37.  
  38. # any remaining lines are unexpected, and probably error messages. These will be printed out and highlighted.
  39. {
  40. print "->" $0 # Unexpected message. Print it
  41. ErrorDetected=1
  42. }
  43.  
  44. END
  45. {
  46. if (ErrorDetected == 1) {
  47. print "Unexpected messages ("->") detected in execution."
  48. exit 2
  49. }
  50. }
  51. '
  52. exit $?
  53.  
  54. out=`command args...` || echo $out
Add Comment
Please, Sign In to add comment