我正在尝试为外部硬盘创建一个自定义的文件/签入签出脚本,但是脚本的一部分来自一台Linux机器,我已经测试过它工作正常,但是使用udevinfo,OSX没有udev,那么有没有提供相同功能的东西呢?
#!/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[@]}"
有人知道其他选择吗?或者用bash在OSX上实现这一点的方法?
最佳答案
#!/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])
关于bash - OSX上udev功能的替代,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2600514/