HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials

HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials (http://www.howtoforge.com/forums/index.php)
-   Programming/Scripts (http://www.howtoforge.com/forums/forumdisplay.php?f=7)
-   -   Create user and email script (http://www.howtoforge.com/forums/showthread.php?t=23969)

TheRudy 7th June 2008 12:15

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


All times are GMT +2. The time now is 20:53.

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