Correct whitespaces

This commit is contained in:
Jeremy Gardais 2017-02-15 14:37:46 +01:00
parent 2928251d4a
commit 85ba2a65dd
1 changed files with 28 additions and 20 deletions

View File

@ -1,32 +1,40 @@
#!/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!
# The first argument must be:
# a file with a mail by line!
# a mail address
# Dependancies:
# ldapsearch (provide by ldap-utils on GNU/Linux)
MAIL_LIST="${1}"
UID_LIST="${MAIL_LIST}_uid"
# Test if the first arg is a existing file
if [ -f "${1}" ]; then
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=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)
#printf '%b' "${index}: ${mail} -> ${uid}\n"
printf '%b' "${uid}\n" >> "${UID_LIST}"
done < "${MAIL_LIST}"
done < "${MAIL_LIST}"
printf '%b' "Please see ${UID_LIST} file\n"
printf '%b' "Please see ${UID_LIST} file\n"
exit 0
else
MAIL="${1}"
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