View Single Post
  #1  
Old 7th June 2008, 11:15
TheRudy TheRudy is offline
Senior Member
 
Join Date: Dec 2005
Posts: 215
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
Code:
#!/bin/sh

# 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}" ]
then
        echo "Email already exists, please try again."
        exit 1
fi;

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

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

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

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

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 13:08.
Reply With Quote
Sponsored Links