我正处于设计脚本的最后阶段,以自动化我的Active Directory绑定,供多人使用。因此,我需要提示输入用户名和密码。我已经成功创建了提示,但想找到一些方法来阻止密码出现在要求输入密码的对话框中(这将远程完成,我不希望密码可见)。
它可以变成星星,圆点,根本不显示,任何东西,我只是需要它不要在视觉上显示,但仍然能够传递给dsconfigad命令。
我已经测试了脚本本身并且它可以正常工作,这是我需要实现它的最后一块。
(请原谅任何额外的评论,我已经从很多不同的来源拼凑了这些评论)
#!/bin/bash
while :; do # Loop until valid input is entered or Cancel is pressed.
user=$(osascript -e 'Tell application "System Events" to display dialog "Enter the network user name:" default answer ""' -e 'text returned of result' 2>/dev/null)
if (( $? )); then exit 1; fi # Abort, if user pressed Cancel.
user=$(echo -n "$user" | sed 's/^ *//' | sed 's/ *$//') # Trim leading and trailing whitespace.
if [[ -z "$user" ]]; then
# The user left the project name blank.
osascript -e 'Tell application "System Events" to display alert "You must enter a user name; please try again." as warning' >/dev/null
# Continue loop to prompt again.
else
# Valid input: exit loop and continue.
break
fi
done
while :; do # Loop until valid input is entered or Cancel is pressed.
netpass=$(osascript -e 'Tell application "System Events" to display dialog "Enter the network password:" default answer ""' -e 'text returned of result' 2>/dev/null)
if (( $? )); then exit 1; fi # Abort, if user pressed Cancel.
netpass=$(echo -n "$netpass" | sed 's/^ *//' | sed 's/ *$//') # Trim leading and trailing whitespace.
if [[ -z "$netpass" ]]; then
# The user left the project name blank.
osascript -e 'Tell application "System Events" to display alert "You must enter a password; please try again." as warning' >/dev/null
# Continue loop to prompt again.
else
# Valid input: exit loop and continue.
break
fi
done
MACNAME=$(scutil --get ComputerName)
sudo dsconfigad -add DOMAIN \
-username $user \
-password $netpass \
-computer $MACNAME \
-mobile disable \
-mobileconfirm disable \
-localhome enable \
-useuncpath enable \
-shell /bin/bash \
-ou OU=Macs,CN=Computers,DC=corp,DC=DOMAIN,DC=net \
-force \
-localpassword LOCALPASS \
-groups "GROUPS"
#sudo rm -- "$0"
答案 0 :(得分:5)
使用with hidden answer
。链接:
osascript -e 'Tell application "System Events" to display dialog "Enter the network password:" with hidden answer default answer ""' -e 'text returned of result' 2>/dev/null