scripts/ur/mail2sesame

41 lines
962 B
Plaintext
Raw Permalink Normal View History

#!/bin/sh
# This script will convert UR1 user mail into UR1 user sesame
2017-02-15 14:37:46 +01:00
# The first argument must be:
# a file with a mail by line!
# a mail address
# Dependancies:
# ldapsearch (provide by ldap-utils on GNU/Linux)
2017-02-15 14:37:46 +01:00
# Test if the first arg is a existing file
if [ -f "${1}" ]; then
MAIL_LIST="${1}"
UID_LIST="${MAIL_LIST}_uid"
2017-02-15 14:37:46 +01:00
touch "${UID_LIST}"
2017-02-15 14:37:46 +01:00
index=0
while read -r mail; do
index=$((index+1))
uid=$(ldapsearch -ZZ -H ldap://ldap.univ-rennes1.fr -LLL '(mail='"${mail}"')' -b "dc=univ-rennes1,dc=fr" -x uid | grep "^uid" | cut -d" " -f2)
2017-02-15 14:37:46 +01:00
#printf '%b' "${index}: ${mail} -> ${uid}\n"
printf '%b' "${uid}\n" >> "${UID_LIST}"
2017-02-15 14:37:46 +01:00
done < "${MAIL_LIST}"
printf '%b' "Please see ${UID_LIST} file\n"
exit 0
else
MAIL="${1}"
2017-02-15 14:37:46 +01:00
printf '%b' "This email address correspond to:\n"
ldapsearch -ZZ -H ldap://ldap.univ-rennes1.fr -LLL '(mail='"${MAIL}"')' -b "dc=univ-rennes1,dc=fr" -x uid | grep "^uid" | cut -d" " -f2
exit 0
fi
exit 0