Created
May 15, 2013 10:12
-
-
Save benoitjpnet/5582952 to your computer and use it in GitHub Desktop.
Add mails account to a server (pack mail evolix)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
regex="([A-Za-zéôçèÉÊ-]+) ([A-Za-zéôçèÉÊ-]+) <([a-zA-Z]){1}[a-z-]+\.([a-z]+)" | |
regex2="<(.*)>" | |
lastuidNumber=3075 | |
while read line; do | |
[[ $line =~ $regex ]] | |
# Get name | |
lastName=${BASH_REMATCH[1]} | |
firstName=${BASH_REMATCH[2]} | |
# Get uid | |
uid=${BASH_REMATCH[3]}${BASH_REMATCH[4]} | |
# Get uidNumber | |
uidNumber=$(($lastuidNumber+1)) | |
lastuidNumber=$uidNumber | |
# Generates password | |
pass=$(apg -n 1) | |
hashedPass=$(slappasswd -s $pass) | |
# Get Mail | |
[[ $line =~ $regex2 ]] | |
mail=${BASH_REMATCH[1]} | |
# Generates ldif | |
cat <<EOT>/tmp/add.ldif | |
dn: uid=$uid,ou=people,dc=boite,dc=com | |
uid: $uid | |
uidNumber: $uidNumber | |
gidNumber: 3000 | |
objectClass: posixAccount | |
objectClass: shadowAccount | |
objectClass: inetOrgPerson | |
objectClass: mailAccount | |
isActive: TRUE | |
isAdmin: FALSE | |
cn: $lastName $firstName | |
loginShell: | |
sn: $lastName $firstName | |
homeDirectory: /home/$uid | |
mailacceptinggeneralid: $uid | |
maildrop: $uid | |
accountActive: TRUE | |
courierActive: TRUE | |
webmailActive: TRUE | |
authsmtpActive: TRUE | |
mail: $mail | |
userPassword: $hashedPass | |
EOT | |
# Add account | |
ldapvi --noquestions --noninteractive --in --add /tmp/add.ldif | |
# Mkdir & chown home | |
mkdir /home/${uid} | |
chown ${uid}:mailusers /home/${uid} | |
# Generates mail | |
subject="Creation du compte $uid" | |
body="Bonjour,\n\n"\ | |
"Un nouveau compte vient d'être créé.\n"\ | |
"Identifiant : $uid\n"\ | |
"Mot de passe : $pass\n"\ | |
"Mail : $mail\n\n"\ | |
"Cordialement,\n"\ | |
"--\nL'équipe Evolix" | |
echo -e $body | mail -s "$subject" [email protected] | |
done < /tmp/mails | |
#/tmp/mails: | |
# | |
#Toto TEST <[email protected]> | |
#Machin TRUC <[email protected]> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment