Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import subprocess
- import xml.etree.ElementTree as ET
- #This is mac only, because I'm using diskutil to find the disk.
- #Other OSs could be added by detecting the OS and using a
- #differnt method for finding the right disk.
- def findDiskMac():
- #Start by finding the list of disks.
- diskUtilOutput = subprocess.check_output(['diskutil list -plist'], shell = True)
- root = ET.fromstring(diskUtilOutput)
- diskList = [child.text for child in root[0][7]]
- #now see which one is a Duo or RTX.
- devices = []
- for disk in diskList:
- try:
- device.append(subprocess.check_output(['diskutil info ' +disk+ ' | grep -e "CRU" -e "Duo" -e "DUO" -e "RTX"']))
- except subprocess.CalledProcessError
- #this means grep didn't find what we were looking for.
- pass
- def testDisks(disks):
- outputText = '' #output is vague to prevent customers lying about the output.
- testHash = "16afa5a9b0e4b08d08ebc0afcc8d53c3\n"
- #adding \n here means that we don't have to clean the string later.
- for disk in disks:
- diskHash = subprocess.check_output(['sudo dd if=/dev/'+disk+ 'count=65535 | md5'], shell = True)
- if diskHash == testHash:
- outputText += disk+" has code 1. " #erased by RAID controller.
- else:
- outputText += disk+" has code 2. " #not all zeroes.
- return outputText
- def main():
- disksToTest = findDiskMac()
- print testDisks(disksToTest)
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement