scripts/mailtosesame

30 lines
714 B
Bash
Executable File

#!/bin/sh
# This script will convert UR1 user mail into UR1 user sesame
# The first argument should be a file with a mail by line!
MAIL_LIST="${1}"
UID_LIST="${MAIL_LIST}_uid"
# Test if the given file exists
if [ -f "${MAIL_LIST}" ]; then
touch "${UID_LIST}"
else
printf '%b' "The fist argument should be a file with one mail/line\n"
exit 1
fi
index=0
while read 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)
#printf '%b' "${index}: ${mail} -> ${uid}\n"
printf '%b' "${uid}\n" >> "${UID_LIST}"
done < "${MAIL_LIST}"
printf '%b' "Please see ${UID_LIST} file\n"
exit 0