0

我正在编写一个执行 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: `        ;;'
4

1 回答 1

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
)
于 2013-09-17T21:14:08.377 回答