Advertisement
Guest User

disk_check.sh

a guest
Aug 24th, 2014
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.04 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # This script checks if a disk|partition is allready an Ceph OSD and
  4. # checks also if the device entered is a block device
  5. #
  6. # Expects a device (/dev/sda) as an argument and NOT a partition
  7. # (/dev/sda1)
  8. #
  9. # Written by Richard Arends, mainly for puppet-ceph:
  10. #   https://github.com/stackforge/puppet-ceph
  11. #
  12. # Exit codes:
  13. #
  14. #   0: An active 'ceph data' partition is found on $DEVICE
  15. #   1: An active 'ceph data' partition is NOT found on $DEVICE
  16. #   100: There was an error with the ceph-disk command
  17. #   101: Device ${DEVICE} is not a block device
  18. #  
  19. DEVICE="$1"
  20.  
  21. doExit() {
  22.     E_CODE=$1
  23.  
  24.     echo $E_CODE
  25.     exit $E_CODE
  26. }
  27.  
  28. ###
  29. # Main
  30. ###
  31. if ! test -b "${DEVICE}"; then
  32.     # Device ${DEVICE} is not a block device
  33.     doExit 101
  34. fi
  35.  
  36. CEPH_DISK_OUTPUT=$(ceph-disk list)
  37. CEPH_DISK_RETVAL=$(echo $?)
  38. if [ $CEPH_DISK_RETVAL -ne 0 ]; then
  39.     # There was an error with the ceph-disk command
  40.     doExit 100
  41. fi
  42.  
  43. CEPH_DISK_LIST_RETVAL=$(echo "${CEPH_DISK_OUTPUT}"|grep -q " *${DEVICE}.*ceph data, active";echo $?)
  44.  
  45. doExit "${CEPH_DISK_LIST_RETVAL}"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement