我正在编写一个执行LDAP搜索的脚本,并从Sun Messaging Server样式的邮件组中读取LDIF文件,并将其转换为mailman样式的配置文件。当我运行我的脚本时,我得到一个意外的令牌错误。这是我从sh -n -v myScript.sh myGroup
选择的输出。
...
# Disallowed Domains
# LDAP: mgrpDisallowedDomain
# mgrpDisallowedDomain: <domain>
# config: reject_these_nonmembers
# reject_these_nonmembers = ['^.@<domain1>', '^.*@<domain2>'...]
LIST_DISALLOWED_DOMAIN=$(
grep "^mgrpDisallowedDomain: " $SOURCE_FILE | sed 's/^mgrpDisallowedDomain: //g' | while read domain
do
echo "'^.@$domain'"
done
)
if [ -n "$LIST_DISALLOWED_DOMAIN" ]
then
echo $LIST_DISALLOWED_DOMAIN | awk '
BEGIN {
print "reject_these_nonmembers = [";
} {
for(i=1;i<=NF;i++){
printf "%s, ", $i;
};
} END {
print "\b\b]\n\n";
}'
fi
# Allowed Senders
# LDAP: mgrpAllowedBroadcaster
# mgrpAllowedBroadcaster: mailto:<email>
# mgrpAllowedBroadcaster: ldap:///uid=<uid>,ou=People,o=csusb.edu,o=edu
# mgrpAllowedBroadcaster: ldap:///cn=<cn>,ou=Groups,o=csusb.edu,o=edu
# config: accept_these_nonmembers
# accept_these_nonmembers = ['<email>', '@<listname>'...]
LIST_ALLOWED_BROADCASTER=$(
grep "^mgrpAllowedBroadcaster: " $SOURCE_FILE | sed 's/^mgrpAllowedBroadcaster: //g' | while read uri
do
case $uri in
mailto:*)
mailto=`echo $uri | cut -d: -f 2`
echo "'$mailto'"
287---->;;
ldap:*uid=*)
user_dn=`echo $uri | sed 's/ldap:.*uid=/uid=/g'`
MAIL_ATTR=`ldapsearch -x -LLL -h $LDAP_HOST -D "$LDAP_BIND_DN" -w $LDAP_BIND_PW -b "$user_dn" "(objectClass=*)" mail | grep "^mail: " | sed 's/^mail: //g'`
echo "'$MAIL_ATTR'"
;;
ldap:*cn=*)
group_dn=`echo $uri | sed s/ldap:.*cn=/cn=/g'`
MAIL_ATTR=`ldapsearch -x -LLL -h $LDAP_HOST -D "$LDAP_BIND_DN" -w $LDAP_BIND_PW -b "$group_dn" "(objectClass=*)" mail | grep "^mail: " | sed 's/^mail: //g' | cut -d'@' -f 1`
echo "'@$MAIL_ATTR'"
;;
esac
done
)
我收到以下错误:
myScript.sh: line 287: syntax error near unexpected token `;;'
myScript.sh: line 287: ` ;;'
答案 0 :(得分:0)
由于您正在运行在命令替换下运行的case语句,因此您必须使用格式case $var in (expr) ... ;; esac
,因为只有一个)
会使shell将其解释为命令替换的结束。
LIST_ALLOWED_BROADCASTER=$(
grep "^mgrpAllowedBroadcaster: " $SOURCE_FILE | sed 's/^mgrpAllowedBroadcaster: //g' | while read uri
do
case $uri in
(mailto:*)
mailto=`echo $uri | cut -d: -f 2`
echo "'$mailto'"
;;
(ldap:*uid=*)
user_dn=`echo $uri | sed 's/ldap:.*uid=/uid=/g'`
MAIL_ATTR=`ldapsearch -x -LLL -h $LDAP_HOST -D "$LDAP_BIND_DN" -w $LDAP_BIND_PW -b "$user_dn" "(objectClass=*)" mail | grep "^mail: " | sed 's/^mail: //g'`
echo "'$MAIL_ATTR'"
;;
(ldap:*cn=*)
group_dn=`echo $uri | sed s/ldap:.*cn=/cn=/g'`
MAIL_ATTR=`ldapsearch -x -LLL -h $LDAP_HOST -D "$LDAP_BIND_DN" -w $LDAP_BIND_PW -b "$group_dn" "(objectClass=*)" mail | grep "^mail: " | sed 's/^mail: //g' | cut -d'@' -f 1`
echo "'@$MAIL_ATTR'"
;;
esac
done
)