Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > Linux Forums > Programming/Scripts

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Thread Tools Display Modes
Old 7th June 2008, 12:15
TheRudy TheRudy is offline
Senior Member
Join Date: Dec 2005
Posts: 216
Thanks: 1
Thanked 7 Times in 5 Posts
Default Create user and email script

Just in case someone will need this, i've made a simple script for myself that creates new user and adds email to the system.

Used in this setup: http://howtoforge.com/forums/showthread.php?t=23522

It's far from perfect but it sure simplifies the job of adding new email

# Creates new user and adds email to the list ;)

echo "================================================";
echo "Hey! This script is used for creating new email.";

echo -n "Enter full email address and press [ENTER]: "
read EMAIL

PRE_EMAIL=$(egrep "^$EMAIL" /etc/postfix/virtusertable)
if [ -n "${PRE_EMAIL}" ]
        echo "Email already exists, please try again."
        exit 1

echo -n "Enter users name, used for system and press [ENTER]: ";
read USER

PRE_USER=$(egrep "^$USER" /etc/passwd)
if [ -n "${PRE_USER}" ]
        echo "User already exists, please try again."
        exit 1

echo -n "Enter folder name and press [ENTER]: ";

PRE_FOLDER=$(egrep ":/home/$FOLDER:" /etc/passwd)
if [ -n "${PRE_FOLDER}" ]
        echo "Folder already exists, please try again."
        exit 1

echo -e "\nCreating user...\n";
useradd -d /home/"$FOLDER" -m -g users "$USER" -s /bin/false
passwd "$USER"
echo -e "Adding email line to /etc/postfix/virtusertable \n"
echo "$EMAIL" "$USER" >> /etc/postfix/virtusertable
echo -e "Running postmap /etc/postfix/virtusertable command... \n"
postmap /etc/postfix/virtusertable
echo -e "Restarting Postfix... \n"
/etc/init.d/postfix restart
echo -e "User was successfully added!\n"
Just save the file, chmod to 755 and run it. It will ask you for info it needs

Last edited by TheRudy; 7th June 2008 at 14:08.
Reply With Quote
The Following 2 Users Say Thank You to TheRudy For This Useful Post:
falko (8th June 2008), ManWithNoName (21st June 2008)
Sponsored Links


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't create email user mzo Installation/Configuration 10 27th February 2008 14:16
Support Tickets - Email End User Xtreem1986 Installation/Configuration 8 11th May 2007 02:47
create eMail Folder right after creating an user? LeoLinux Installation/Configuration 9 15th April 2007 16:57
new email user , impossible create carlainz General 1 25th November 2006 01:09
Automaticaly create email accounts marc Programming/Scripts 8 21st May 2006 22:24

All times are GMT +2. The time now is 12:15.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.