sesame2mail: can now convert one user ID passed in arg to it's mail address
This commit is contained in:
parent
999bc04056
commit
58d069443d
|
@ -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.
|
||||
|
|
34
sesame2mail
34
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"
|
||||
|
||||
# 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=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}"
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue