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.
Reply
 
Thread Tools Display Modes
  #1  
Old 7th June 2008, 11: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
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
The Following 2 Users Say Thank You to TheRudy For This Useful Post:
falko (8th June 2008), ManWithNoName (21st June 2008)
Sponsored Links
Reply

Bookmarks

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 13:16
Support Tickets - Email End User Xtreem1986 Installation/Configuration 8 11th May 2007 01:47
create eMail Folder right after creating an user? LeoLinux Installation/Configuration 9 15th April 2007 15:57
new email user , impossible create carlainz General 1 25th November 2006 00:09
Automaticaly create email accounts marc Programming/Scripts 8 21st May 2006 21:24


All times are GMT +2. The time now is 10:16.


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