sesame2mail: can now convert one user ID passed in arg to it's mail address

This commit is contained in:
Jeremy Gardais 2017-01-17 18:27:37 +01:00
parent 999bc04056
commit 58d069443d
3 changed files with 34 additions and 19 deletions

View File

@ -6,6 +6,7 @@
2. [Scripts](#scripts) 2. [Scripts](#scripts)
* [Proxmox](#proxmox) * [Proxmox](#proxmox)
* [Grav](#grav) * [Grav](#grav)
* [Sesame2mail](#sesame2mail)
## Overview ## Overview
@ -40,3 +41,11 @@ A daily cron to check if [Grav][grav website] got available updates.
[grav website]: https://getgrav.org/ [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.

0
TODO.md Normal file
View File

View File

@ -1,32 +1,38 @@
#!/bin/sh #!/bin/sh
# This script will convert UR1 user sesame into UR1 user mail # 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: # Dependancies:
# ldapsearch (provide by ldap-utils on GNU/Linux) # ldapsearch (provide by ldap-utils on GNU/Linux)
UID_LIST="${1}" if [ -f "${1}" ]; then
MAIL_LIST="${UID_LIST}_mail"
UID_LIST="${1}"
MAIL_LIST="${UID_LIST}_mail"
printf '%b' "Convert the list of ID in **${UID_LIST}** to mail\n"
# Test if the given file exists
if [ -f "${UID_LIST}" ]; then
touch "${MAIL_LIST}" touch "${MAIL_LIST}"
else
printf '%b' "The fist argument should be a file with one mail/line\n"
exit 1
fi
index=0 index=0
while read uid; do while read uid; do
index=$((index+1)) 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) 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}" printf '%b' "${mail}\n" >> "${MAIL_LIST}"
done < "${UID_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
printf '%b' "Please see ${MAIL_LIST} file\n"
exit 0 exit 0