Guest User

Untitled

a guest
Jun 22nd, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. set -Cu
  4.  
  5. based=$(dirname $0)/..
  6. pname=$(basename $0)
  7. stime=$(date +%Y%m%d%H%M%S%Z)
  8.  
  9. # exec 3>&2
  10. logd=$based/log
  11. exec 3>&2 2>$logd/$pname.$stime.$$.log
  12. set -vx
  13.  
  14. MSG() {
  15. echo "$pname $stime $(date +%Y%m%d%H%M%S%Z) $@" >&3
  16. }
  17.  
  18. tmpd=$(mktemp -d --suffix=".$pname.$stime.$$")/
  19. if [ 0 -ne "$?" ] ; then
  20. MSG FATAL can not make temporally directory.
  21. exit 1
  22. fi
  23.  
  24. trap 'BEFORE_EXIT' EXIT
  25. BEFORE_EXIT() {
  26. rm -rf $tmpd
  27. }
  28.  
  29. IS_ERROR() {
  30. echo ${PIPESTATUS[@]} |
  31. tr ' \t' '\n' |
  32. grep -qv '^0$'
  33. }
  34. ################################################################
  35.  
  36. MSG INFO This is a message.
  37.  
  38. true
  39. IS_ERROR && MSG FATAL unreachable && exit 1
  40.  
  41. ################################################################
  42. exit 0
Add Comment
Please, Sign In to add comment