scripts/ur/sesame2mail

39 lines
929 B
Bash
Executable File
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/sh
# This script will convert UR1 user sesame into UR1 user mail
# The first argument should be a file with a uid by line!
# OR a USER sesame (id).
# Dependancies:
# ldapsearch (provide by ldap-utils on GNU/Linux)
if [ -f "${1}" ]; then
UID_LIST="${1}"
MAIL_LIST="${UID_LIST}_mail"
printf '%b' "Convert the list of ID in **${UID_LIST}** to mail\n"
touch "${MAIL_LIST}"
index=0
while read -r uid; do
index=$((index+1))
mail=$(ldapsearch -ZZ -H ldap://ldap.univ-rennes1.fr -LLL '(uid='"${uid}"')' -b "dc=univ-rennes1,dc=fr" -x mail | grep "^mail" | cut -d" " -f2)
printf '%b' "${mail}\n" >> "${MAIL_LIST}"
done < "${UID_LIST}"
printf '%b' "Please see ${MAIL_LIST} file\n"
else
USER_ID="${1}"
printf '%b' "This sesame correspond to:\n"
ldapsearch -ZZ -H ldap://ldap.univ-rennes1.fr -LLL '(uid='"${USER_ID}"')' -b "dc=univ-rennes1,dc=fr" -x mail | grep "^mail" | cut -d" " -f2
fi
exit 0