From 58d069443d458e22485ac0cb21e6ae9d497bbd14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gardais=20J=C3=A9r=C3=A9my?= Date: Tue, 17 Jan 2017 18:27:37 +0100 Subject: [PATCH] sesame2mail: can now convert one user ID passed in arg to it's mail address --- README.md | 9 +++++++++ TODO.md | 0 sesame2mail | 44 +++++++++++++++++++++++++------------------- 3 files changed, 34 insertions(+), 19 deletions(-) create mode 100644 TODO.md diff --git a/README.md b/README.md index e88cd8e..eb46d16 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ 2. [Scripts](#scripts) * [Proxmox](#proxmox) * [Grav](#grav) + * [Sesame2mail](#sesame2mail) ## Overview @@ -40,3 +41,11 @@ A daily cron to check if [Grav][grav website] got available updates. [grav website]: https://getgrav.org/ + +### Sesame2mail + +Give a user's mail address from it's user ID (sesame). + +The first argument can be : +* A file with a list of user ID (sesame), one per line. +* A user ID (sesame), only one. diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..e69de29 diff --git a/sesame2mail b/sesame2mail index 26ddf21..58c88ce 100755 --- a/sesame2mail +++ b/sesame2mail @@ -1,32 +1,38 @@ #!/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! +# 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) -UID_LIST="${1}" -MAIL_LIST="${UID_LIST}_mail" +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 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" -# 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 + 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 -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