Advertisement
Guest User

Untitled

a guest
Dec 19th, 2014
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. ssh root@kvmsrv 'virsh shutdown $host 2> /dev/null; virsh destroy $host 2> /dev/null; sleep 2; virsh undefine $host 2> /dev/null'
  2.  
  3. # Also needs to be run on remote machine
  4. # to disconnect iscsi
  5. iscsiadm -m session | grep $host
  6. if [ $? == 0 ]; then
  7. iscsiadm -m node -T $stserver.$host -u
  8. fi
  9.  
  10. # then on local machine
  11. tid=`ssh root@storage1 'cat /proc/net/iet/volume' | grep $host | head -1 | awk '{print $1}' | awk -F: '{print $2}'`
  12. if [ $tid ]; then
  13. echo "Deleting tid:$tid from $stserver."
  14. ssh root@$stserver "ietadm --op delete --tid=$tid"
  15. fi
  16.  
  17. ssh root@kvmsrv < virsh-shutdown-remote.sh
  18.  
  19. iscsiadm -m session | grep $host
  20. if [ $? == 0 ]; then
  21. iscsiadm -m node -T $stserver.$host -u
  22. fi
  23.  
  24. iscsiadm -m session | grep $host && iscsiadm -m node -T $stserver.$host -u
  25.  
  26. ssh root@kvmsrv <<EOF
  27. virsh shutdown $host 2> /dev/null
  28. virsh destroy $host 2> /dev/null
  29. sleep 2
  30. virsh undefine $host 2> /dev/null
  31.  
  32. # to disconnect iscsi
  33. iscsiadm -m session | grep $host
  34. if [ $? == 0 ] ; then
  35. iscsiadm -m node -T $stserver.$host -u
  36. fi
  37. EOF
  38.  
  39. virsh -c qemu+ssh://root@kvmsrv/system destroy host
  40.  
  41. ssh root@kvmsrv '
  42. cmd1
  43. cmd2
  44. cmd3
  45. '
  46.  
  47. ssh localhost '
  48. echo hi
  49. whoami
  50. ls -ld /
  51. var="'''"
  52. echo "$var"
  53. if [ $? == 0 ]; then
  54. echo "escaping single quote worked"
  55. fi
  56. '
  57.  
  58. # get single quote from file and print it
  59. echo "'" > sqfile
  60. ssh localhost '
  61. #set -xv
  62. echo hi
  63. cat sqfile
  64. var="$(cat sqfile)"
  65. echo "$var"
  66. '
  67.  
  68. # pass a single quote to the remote host and print it
  69. # while keeping the outer single quotes for the ssh command
  70. escsquote="'''"
  71. squote="'"
  72. squote="'${squote//'/${escsquote}}'" # bash
  73.  
  74. ssh localhost 'sh -c '''
  75. #set -xv
  76. echo hi
  77. echo "$1"
  78. '''' _ "$squote"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement