LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 02-09-2004, 07:36 AM   #1
O_Chaos
LQ Newbie
 
Registered: Feb 2004
Posts: 4

Rep: Reputation: 0
Need help finishing Bash Script to add new user and map virtual e-mail info.


Hi, I am writing a bash script that will ask some questions to add a new user, then call the adduser bash script with the variables entered..
I then want to edit the /etc/mail/virtusertable and /etc/mail/genericstable files to set up my e-mail addresses...

The files must be entered like this:

mail@abc.com user1 <-- this is for the virtable.
user1 mail.abc.com <-- the genericstable.

Here is where I am so far, this script sucessfully creates the user, but now I need to write to these files and can't figure it out... I am still learning bash scripting and found most of this code, and modified it to meet my needs so far. Any help would be greatly appreciated.


#!/bin/sh

echo ================================
echo Please enter new users full name
echo ================================
read fullname
echo
echo ===============================
echo Please enter new users Username
echo ===============================
read name
grep -i $name /etc/passwd;echo $? > /dev/null |grep $name
if grep -i $name /etc/passwd
then
echo =========================================
echo The username you are attempting to enter
echo either already exists or is invalid.
echo Please verify username.
echo =========================================
exit 1
fi

echo
echo ====================================
echo The following userids are available
echo Please use the first available one:
echo ====================================
cut -d: -f3 /etc/passwd > /tmp/used
i=550
while [ $i -re 500 ]
do
grep "^$i$" /tmp/used > /dev/null 2>&1
if [ $? -ne 0 ]
then
#echo "UID $i is available for use"
fi
i=`expr $i - 1`
done
rm /tmp/used
echo ===============================
echo Please enter new users userid
echo ===============================
read uid
echo ===============================
echo Please enter new users Password
echo ===============================
read password

clear
echo =====================================
echo Group numbers are as follows:
echo =====================================
echo Group1 = 501
echo Group2 = 502
echo =====================================
echo Enter the group number for this user:
echo =====================================
read group

clear
echo =========================================
echo The following information will be used to
echo create the new user. Ensure that all the
echo information presented is correct. If
echo there are problems with the information
echo press CTRL + C to cancel this process and
echo start over again.
echo ==========================================
echo
echo "Users full name is : $fullname"
echo "Users username is : $name"
echo "Users UID is : $uid"
echo "Users Password is : $password"
echo "Users group id is : $group"
echo "Users work shell is : /bin/bash"
echo "Users home directory is : /home/$name"
echo "Users Comment is : $fullname"
echo
echo ========================================
echo Press enter to continue creating account
read _enter
echo
echo
echo ========================================
echo The account is now being created .......
echo ========================================
adduser -u $uid -g $group -c "$fullname" $name -p $password
 
Old 02-09-2004, 04:06 PM   #2
O_Chaos
LQ Newbie
 
Registered: Feb 2004
Posts: 4

Original Poster
Rep: Reputation: 0
I got this

I finished this... I cant believe it took me so long to find something so easy...

I will post it, so if some other noob is looking to build a script that will add a new user and assign virtual e-mail addresses for thier sendmail server, they will have it...

All I had to do was enter an input for the mail address and these 2 lines..

echo $mail $user >> /etc/mail/virtusertable
echo $user $mail >> /etc/mail/genericstable
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to add numbers in a formatted file via a bash script? zero79 Linux - General 8 12-24-2010 05:48 PM
add user bash script noir911 Programming 4 08-13-2005 08:24 AM
Trying to read named.conf forwarders info in bash script. scottman Programming 4 09-11-2004 09:38 PM
Bash script: add all numbers from command output wi-Z-art Programming 2 08-06-2003 09:16 AM
how to add virtual user & domain on sendmail? earl Linux - Networking 2 07-30-2002 10:22 PM


All times are GMT -5. The time now is 04:38 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration