Auto Mounting Network Drives

草稿macOSNASMounting

mounter.sh

RED="\\033[1;31m" GREEN="\\033[1;32m" NOCOLOR="\\033[0m" connections=( "NAME_OF_DRIVE|USERNAME|NAME_OF_NETWORK_DEVICE._smb._tcp.local./LOCAL_DRIVE_NAME" "Backup|john|DataCentral._smb._tcp.local./Backup" ) currentusername=$(stat -f%Su /dev/console) for item in "${connections[@]}" do item_name=$(echo "${item}"|awk -F "|" '{print $1}') item_user=$(echo "${item}"|awk -F "|" '{print $2}') item_conn=$(echo "${item}"|awk -F "|" '{print $3}') item_pass=$(security find-internet-password -D "Network password" -l "SMB-${item_name}" -w) if [ -d "/Volumes/${item_name}" ]; then echo "${RED}Mounting point \\"${item_name}\\" already exists, skipping ${NOCOLOR}" continue; fi if [ -z "${item_pass}" ]; then echo "" echo "${RED}Keychain Lookup failed${NOCOLOR}" echo "Please provide Password for:" echo " User : ${GREEN}${item_user}${NOCOLOR}" echo " Name : ${GREEN}SMB-${item_name}${NOCOLOR}" echo " Conn : ${GREEN}SMB-${item_conn}${NOCOLOR}" security add-internet-password -a $currentusername -D "Network password" -l "SMB-${item_name}" -s "smb://${item_conn}" -w fi echo "Mounting ${item_name}" mkdir -p /Volumes/${item_name} mount -t smbfs //${item_user}:$(security find-internet-password -D "Network password" -l "SMB-${item_name}" -w)@${item_conn} /Volumes/${item_name} done

mounter.plist

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>com.user.loginscript</string> <key>ProgramArguments</key> <array><string>/Users/contmp/Library/Mobile Documents/com~apple~CloudDocs/macOS/Zsh/mounter.sh</string></array> <key>RunAtLoad</key> <true/> </dict> </plist>
元等級

Auto Mounting Network Drives
日期
2021年7月22日
超過 3 年前
語言
de
更新於
2024年10月20日