Guest User

Untitled

a guest
Aug 18th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #####################################################################################
  4. ## ##
  5. ## ##
  6. ## file : all-dvd-eject.sh ##
  7. ## description : ejects all DVDs from VMs running in a XenServer pool ##
  8. ## ##
  9. ## parameter : eject|dry ##
  10. ## - eject will throw out all mapped DVD drives ##
  11. ## - "dry" will show you which VM has mapped a DVD ##
  12. ## ##
  13. ## example: ./all-dvd-eject.sh eject ##
  14. ## ./all-dvd-eject.sh dry ##
  15. ## ##
  16. ## known issues: - The script doesn't work on VMs namend "Control" ##
  17. ## ##
  18. ## Use this script in your own risk and be careful to use it in productive ##
  19. ## environments. This script was tested in a very simple way and just on ##
  20. ## XenServer 5.5 with update 1. Therefore if you want to use it be sure ##
  21. ## to do intensive tests for your environment. ##
  22. ## ##
  23. ## copyright (c) Jens Brunsen, Citrix Systems ##
  24. #####################################################################################
  25.  
  26. echo
  27.  
  28. if [ $# -gt 0 ] ; then
  29.  
  30. VMLIST=`xe vm-list | grep "uuid ( RO) " | awk '{print $5}'`
  31.  
  32. for VM in $VMLIST
  33. do
  34. VMNAME=`xe vm-list uuid=$VM | grep "name-label ( RW)" | awk '{print $4}'`
  35. if [ "$VMNAME" != "Control" ] ; then
  36. DVDSTATE=`xe vm-cd-list uuid=$VM | grep "empty ( RO)" | awk '{print $4}'`
  37.  
  38. if [ "$1" = "eject" ] ; then
  39. if [ "$DVDSTATE" = "false" ] ; then
  40. xe vm-cd-eject uuid=$VM
  41. echo "$VMNAME : DVD/ISO ejected"
  42. fi
  43. fi
  44.  
  45. if [ "$1" = "dry" ] ; then
  46. if [ "$DVDSTATE" = "false" ] ; then
  47. echo "$VMNAME : DVD/ISO attached"
  48. else
  49. echo "$VMNAME : empty"
  50. fi
  51. fi
  52. fi
  53. done
  54.  
  55. else
  56. echo all-dvd-eject.sh:
  57. echo " error: Missing parameter."
  58. echo " usage: all_dvd_eject [eject|dry]"
  59. fi
  60.  
  61. echo
Add Comment
Please, Sign In to add comment