我有一个简单的 shell 脚本,可以针对 Apple Open Directory (LDAP) 服务器测试密码是否正确(或不正确)。
我想要的只是丢失 gobblygook 错误消息“节点/LDAPv3/1 的身份验证...”,而是插入我自己的语言,例如“密码不匹配”。
这是现在发生的事情:
bash-3.2# test-password
Enter username you'd like to test password for:
jdoe
Enter Password to test for jdoe
asdasdasd
Authentication for node /LDAPv3/127.0.0.1 failed. (-14090, eDSAuthFailed)
<dscl_cmd> DS Error: -14090 (eDSAuthFailed)
我更喜欢的是:
bash-3.2# test-password
Enter username you'd like to test password for:
jdoe
Enter Password to test for jdoe
asdasdasd
Password matches!
所以我只需要知道一种方法,以便消除标准输出错误消息......
这是脚本:
#!/bin/bash
PATH=/bin:/usr/bin:/sbin:/usr/sbin export PATH
echo
echo Enter username you\'d like to test password for:
read USERNAME
echo
echo Enter Password to test for "$USERNAME"
read PASSWORD
/usr/bin/dscl /LDAPv3/127.0.0.1 auth $USERNAME $PASSWORD
if [ "$?" = "0" ]; then
echo "Password is correct"
exit 0
fi