Advertisement
Guest User

Untitled

a guest
Oct 3rd, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. set -e
  4. set -u
  5. #set -x
  6.  
  7. if [ $# -lt 3 -o $# -gt 6 ]; then
  8. echo "Usage: $0 username password host [query_port=10011] [input_file=snapshot.txt] [virtual server id=1]"
  9. exit -1
  10. fi
  11.  
  12. USER="$1"
  13. PASS="$2"
  14. HOST="$3"
  15. PORT="10011"
  16. INPUT_FILE="snapshot.txt"
  17. SID=1
  18. if [ $# -gt 3 ]; then
  19. PORT="${4}"
  20. fi
  21. if [ $# -gt 4 ]; then
  22. INPUT_FILE="${5}"
  23. fi
  24. if [ $# -gt 5 ]; then
  25. SID="${6}"
  26. fi
  27.  
  28. if [ ! -f ${INPUT_FILE} ]; then
  29. echo "could not find input file ${INPUT_FILE}, aborting"
  30. exit -2
  31. fi
  32. ( echo "use ${SID}"; echo "login ${USER} ${PASS}"; echo -n "serversnapshotdeploy "; cat ${INPUT_FILE}; echo; echo "quit" ) | nc ${HOST} ${PORT} > snapshot_apply.txt
  33. if [ ! "`cat snapshot_apply.txt | grep "error id=0 msg=ok" | wc -l | sed 's/ .*//'`" = 4 ]; then
  34. echo "Echo unable to apply the snapshot"
  35. echo "This is what we got as answer to the commands use, login, serversnapshotdeploy, quit:"
  36. cat snapshot_apply.txt
  37. rm snapshot_apply.txt
  38. exit -3
  39. fi
  40.  
  41. rm snapshot_apply.txt
  42.  
  43. echo "Successfully applied snapshot"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement