Advertisement
Pirsqed

Untitled

Aug 20th, 2015
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.57 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import subprocess
  4. import xml.etree.ElementTree as ET
  5.  
  6.  
  7. #This is mac only, because I'm using diskutil to find the disk.
  8. #Other OSs could be added by detecting the OS and using a
  9. #differnt method for finding the right disk.
  10.  
  11. def findDiskMac():
  12.     #Start by finding the list of disks.
  13.     diskUtilOutput = subprocess.check_output(['diskutil list -plist'], shell = True)
  14.     root = ET.fromstring(diskUtilOutput)
  15.     diskList = [child.text for child in root[0][7]]
  16.     #now see which one is a Duo or RTX.
  17.     devices = []
  18.     for disk in diskList:
  19.         try:
  20.             device.append(subprocess.check_output(['diskutil info ' +disk+ ' | grep -e "CRU" -e "Duo" -e "DUO" -e "RTX"']))
  21.            
  22.         except subprocess.CalledProcessError
  23.         #this means grep didn't find what we were looking for.
  24.             pass
  25.    
  26. def testDisks(disks):
  27.     outputText = '' #output is vague to prevent customers lying about the output.
  28.     testHash = "16afa5a9b0e4b08d08ebc0afcc8d53c3\n"
  29.     #adding \n here means that we don't have to clean the string later.
  30.     for disk in disks:
  31.         diskHash = subprocess.check_output(['sudo dd if=/dev/'+disk+ 'count=65535 | md5'], shell = True)
  32.         if diskHash == testHash:
  33.             outputText += disk+" has code 1. " #erased by RAID controller.
  34.         else:
  35.             outputText += disk+" has code 2. " #not all zeroes.
  36.            
  37.        
  38.     return outputText
  39.  
  40. def main():
  41.     disksToTest = findDiskMac()
  42.     print testDisks(disksToTest)
  43.    
  44.  
  45. if __name__ == '__main__':
  46.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement