开发者

Alternative to udev functionality on OSX

I'm trying to create a custom file/check in check out script for external hardrives, however part of the script is from a Linux machine, which I have tested works fine, but uses udevinfo, OS X doesn't have udev, so is there anything that offers the same functionality?

#!/bin/bash
declare -a EXTERNAL_DISKS
declare -a INTERNAL_DISKS

for disk in /dev/[sh]d[a-z]; do
     eval `udevinfo -q env -n $disk`
     [ "$ID_BUS" = "usb" ] && EXTERNAL_DISKS=( ${EXTERNAL_DISKS[@]} $disk )
     [ "$ID_BUS" = "scsi" ] && INTERNAL_DISKS=( ${INTERNAL_DISKS[@]} $disk )
 done

 echo "Internal disks: ${INTERNAL_DISKS[@]}"
 echo "External disks: ${EXTERNAL_DISKS[@]}"

Anybody know any alternatives? Or a way this co开发者_运维百科uld be accomplished on OSX using bash?


#!/usr/bin/env python
from plistlib import readPlistFromString as rPFS
from subprocess import *

def shell(cmd):
    return Popen(cmd.split(), stdout=PIPE).communicate()[0]

disks = {False: [], True: []}   
for disk in rPFS(shell('diskutil list -plist'))['WholeDisks']:
    disks[rPFS(shell('diskutil info -plist ' + disk))['Internal']].append(disk)

print "Internal disks: " + ' '.join(disks[True])    
print "External disks: " + ' '.join(disks[False])    


IOKit manages devices, DiskArbitration manages mass storage devices on top of that. Neither has much in the way of a scripting interface.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜