Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用bash脚本将多个flashdrive列入白名单?_Bash_Macos - Fatal编程技术网

如何使用bash脚本将多个flashdrive列入白名单?

如何使用bash脚本将多个flashdrive列入白名单?,bash,macos,Bash,Macos,我创建了一个脚本,可以检测是否插入了闪存驱动器。问题是它只允许一个闪存驱动器,你知道我如何允许多个闪存驱动器吗?udev不是我的选择,因为我使用的是macos # !/bin/bash #Declare Variables NUM_NOW=`ls -1 /Volumes | awk '{ cnt++ }END { print cnt }'` CUR_FD=`find /Volumes -maxdepth 1 -mindepth 1 -type d | cut -d / -f 3` GET_I

我创建了一个脚本,可以检测是否插入了闪存驱动器。问题是它只允许一个闪存驱动器,你知道我如何允许多个闪存驱动器吗?udev不是我的选择,因为我使用的是macos

# !/bin/bash

#Declare Variables
NUM_NOW=`ls -1 /Volumes  | awk '{ cnt++ }END { print cnt }'`
CUR_FD=`find /Volumes -maxdepth 1 -mindepth 1 -type d | cut -d / -f 3`
GET_IP=$(ifconfig en1 | awk '$1 == "inet" { print $2 }')
GET_USR=$(whoami)
VAL_FD=$(ls -l /Volumes | grep -o SAMPLE)

#Checks if the Flash drive is valid
if [[ $VAL_FD = "SAMPLE" ]]; then
  echo "${CUR_FD} IS valid flash drive"
exit 0
elif [[ "$NUM_NOW" -gt "1" ]]; then
  echo "${CUR_FD} IS INSERTED PLEASE REMOVE IT "
  osascript -e 'display notification "Successfully ejected the Flash Drive" with title "Personal Storage was detected"'
  mail -s "Personal Storage was Detected on this IP ${GET_IP}" sample@gmail.com

  hdiutil detach -force /Volumes/${CUR_FD}
fi

谢谢。我很欣赏你的想法

我想我用case语句解决了我的问题

 # !/bin/bash

#Declare Variables
CUR_FD=`find /Volumes -maxdepth 1 -mindepth 1 -type d | cut -d / -f 3`
GET_IP=$(ifconfig en1 | awk '$1 == "inet" { print $2 }')
GET_USR=$(whoami)

#Check if Variable is empty
[ -z "$CUR_FD" ] && exit 0

case "$CUR_FD" in
  Sample | sample)
          echo "${CUR_FD} IS valid flash drive"
          ;;
          *)
            echo "${CUR_FD} IS INSERTED PLEASE REMOVE IT "
            mail -s "Personal Storage was Detected on this IP ${GET_IP}" machines.sample@gmail.com
            ~/Projects/repo/lib/hipchatNotify.sh verylow note "$GET_USR tried to insert a Personal Storage with this IP: $GET_IP" true
            hdiutil detach -force /Volumes/${CUR_FD}
            osascript -e 'display notification "Successfully ejected the Flash Drive" with title "Personal Storage was detected"'
            ;;
    esac

对我来说,这似乎是一个系统管理员的问题;但是,同样,flashdrive和usb驱动器在安装时是否会自动列入黑名单或不可写入?不,安装后,flashdrive将被弹出,但有效的闪存驱动器除外。我认为您最好使用udev规则。udev不适用于macos@RamanSailopal。