From 529a7a02fba5cdd33d01c142ca7bbd1a96b0228e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gardais=20J=C3=A9r=C3=A9my?= Date: Fri, 1 Jul 2016 14:58:06 +0200 Subject: [PATCH] Add a script to get user's mail from it's UID (LDAP UR1). --- sesame2mail | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100755 sesame2mail diff --git a/sesame2mail b/sesame2mail new file mode 100755 index 0000000..26ddf21 --- /dev/null +++ b/sesame2mail @@ -0,0 +1,32 @@ +#!/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! + +# Dependancies: +# ldapsearch (provide by ldap-utils on GNU/Linux) + +UID_LIST="${1}" +MAIL_LIST="${UID_LIST}_mail" + +# Test if the given file exists +if [ -f "${UID_LIST}" ]; then + touch "${MAIL_LIST}" +else + printf '%b' "The fist argument should be a file with one mail/line\n" + exit 1 +fi + +index=0 +while read 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' "${index}: ${mail} -> ${uid}\n" + printf '%b' "${mail}\n" >> "${MAIL_LIST}" + +done < "${UID_LIST}" + +printf '%b' "Please see ${MAIL_LIST} file\n" + +exit 0