Created
July 1, 2014 12:50
-
-
Save benoitjpnet/58f8cd773dcf3b27c5f7 to your computer and use it in GitHub Desktop.
add mails vmail
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="(.*);(.*);(.*)" | |
#regex2=";([^\"]+)" | |
lastuidNumber=2024 | |
while read line; do | |
[[ $line =~ $regex ]] | |
# Get name | |
name=${BASH_REMATCH[2]} | |
# Get uid | |
uid=${BASH_REMATCH[1]} | |
# Get uidNumber | |
uidNumber=$(($lastuidNumber+1)) | |
lastuidNumber=$uidNumber | |
# Generates password | |
pass=$(apg -n 1) | |
hashedPass=$(slappasswd -s $pass) | |
# Get Mail | |
mail=${BASH_REMATCH[1]} | |
# Get Alias | |
alias=${BASH_REMATCH[3]} | |
# Generates ldif | |
cat <<EOT>/tmp/add1.ldif | |
dn: uid=${mail},cn=domaine.com,dc=serveur,dc=evolix,dc=net | |
uid: $mail | |
uidNumber: $uidNumber | |
gidNumber: 5001 | |
objectClass: posixAccount | |
objectClass: organizationalRole | |
objectClass: mailAccount | |
isActive: TRUE | |
isAdmin: FALSE | |
cn: $name | |
homeDirectory: /home/vmail/domaine.com/${mail%@domaine.com}/ | |
maildrop: $mail | |
accountActive: TRUE | |
courierActive: TRUE | |
webmailActive: TRUE | |
authsmtpActive: TRUE | |
userPassword: $hashedPass | |
mailacceptinggeneralid: $mail | |
EOT | |
touch /tmp/add2.ldif | |
alias2=$(echo $alias | tr -s ',' ' ') | |
for mailA in $alias2; do | |
echo "mailacceptinggeneralid: ${mailA}@domaine.com" >> /tmp/add2.ldif | |
done | |
# Add account | |
cat /tmp/add1.ldif /tmp/add2.ldif > /tmp/add.ldif | |
ldapvi --noquestions --noninteractive --in --add /tmp/add.ldif | |
rm /tmp/add*.ldif | |
# Mkdir & chown home | |
# echo mkdir /home/${uid} | |
# echo 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] | |
mail -s "Initialisation compte" $mail <<< "Boîte mail initialisé" | |
done < ./mails2.csv |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment