You are the System Administrator for a large organisation for the manufacture of gadgets for the gadgets industry. In order to make your task easier, you are to write a Bash shell script called “accounts”, which creates and maintains user accounts on a Linux system.

The Linux system has 10 user groups for users that work within the following areas:
finance, purchasing, manufacture, test, shipping, hr, sales, repair, research, development. Occasionally, you get a composite file from HR that lists new members of staff but also you receive a composite file that lists staff that has been made
redundant. The script should adhere to the following guidelines:
· The script must be a single script, i.e. it must not be multiple scripts that call one another. Comments where necessary must be included to explain operation.
· Place your Name and DCU ID at the top of the script.

· You must test your script on a computer in S212 that has SUSE 10.x installed. DO NOT assume that if it runs on Cygwin that it will run on Linux!

· The Bash shell should be the default user shell.

· New UIDs start at 5000 and new GIDs start at 1000

· A check must be done to avoid duplication of; usernames, UID, groups, GID.

· Usernames are created in lowercase, with max 8 characters. The username is created using a combination of the last name characters followed by the 1st character from first name, e.g. Joe Goldsmith would be goldsmij.

· User home directories, with permissions drwx–x–x, are set up within the home/groupname directories, e.g. /home/research, /home/finance, etc.
· Entries in the /etc/aliases file should be made to allow “Human Readable” email addresses, e.g. joe.goldsmith:goldsmij.

· A user’s public_html directory, with permissions drwxr-xr-x , should be created in each user’s home directory.

· Password aging should be applied with a time value of 50 days.

· Users should be forced to change their passwords at there first login.

· The passwdkey binary is used to generate the 13 character encrypted password entry for the /etc/shadow file. It takes one argument, the password in plain text, and returns the encrypted password.

· The script file must manipulate the various system files directly without calling the system utilities like; useradd, userdel, etc.
· At beginning of your script, set the following variables to allow your script to
be portable to any system:
1) etcdir=$HOME/assign2/etc
2) homedir=$HOME/assign2/home
3) keygen=$HOME/assign2/passwdkey
4) hrfile=$HOME/assign2/hrfile
· Because your script will be run by you as a standard user, then obviously the chown and newaliases utilities, when called upon, will fail to run. However, you must still include the code to call these utilities at the appropriate location within the script so that user root can run the full script. This can be done by examining the variable $USER and if it returns root, then these utilities may be run, otherwise they are skipped over and a warning “Must be root to run the chown or newaliases utilities” is displayed.

· When your script is run, a menu should be presented on screen as follows:

Please select option that you require:

1) Create new user group

2) Create new user account

3) Delete user account

4) Create multiple user accounts from formatted file

5) Delete multiple user accounts from formatted file

6) Suspend user account

7) Re-Instate user account

8) Make user a member also of another group

9) Show home directory space usage for all users

10) Exit

· When a new user group is formed, a subdirectory with that name must also be
created within the home directory.

· Selecting a menu item should, where appropriate, lead to other submenus.
o For 2 or 8 it would be appropriate to show groups that users can join.
o For 3 it would be appropriate to show users on system.
o For 6 or 8 it would be appropriate to show non-suspended users on system
o For 7 it would be appropriate to show suspended users on system

Accounts File

#!/bin/bash
#Sameer Kumar
#53129300
#DME4
#Assignment 2 -  Account Managment Script
#EE438
#05/4/2007
#initialise  variables
etcdir=$HOME/assign2/etc
homedir=$HOME/assign2/home
keygen=$HOME/assign2/passwdkey
hrfile=$HOME/assign2
#interface
echo ”    “
echo “Welcome to the Account Management  Program”
echo ”    “
echo “Please select the option that you  require (1 -10) and press enter”
echo ”    “
echo “1. Create a new  user group”
echo ”    “
echo “2. Create a new user account”
echo  ”    “
echo “3. Delete a user account”
echo ”    “
echo “4.  Create multiple user accounts from formatted file”
echo ”    “
echo  “5. Delete multiple user accounts from formatted file”
echo ”    “
echo  “6. Suspend a user account”
echo ”    “
echo “7. Re-instate user  account”
echo ”    “
echo “8. Make a user a member also of another  group”
echo ”    “
echo “9. Show home directory space usage for  all users”
echo ”    “
echo “10. Exit”
echo ”    “
read  reply;
echo ”    “
#################################################################################################
#1. create new user group
if [ "$reply" = 1 ]; then
clear
echo  “Currently there are the following user groups :”
#list characters,  find, read,
ls -l $homedir|grep “^d”|cut -c 50-80
echo “Enter the  name for the new user group :”
read groupselection
groupselection=`echo$groupselection|tr[:upper:][:lower:]`
val=1
while[  "$val" = 1 ]; do
#if the user group is in the group file
if[  `grep -w $groupselection $etcdir/group|cut -d":" -f1` ]; then
echo  “Sorry that is a duplicate user group”
echo “Please choose a  different name or press z to go back to the main menu”
read answer
#make them lowercase
answer=`echo $answer|tr[:upper:][:lower:]`
if[  "$answer" = z ];then
#return to the main menu
./accounts
else
groupselection=$answer
fi
val=1
else
val=0
fi
done
#if there is the existing line, take last id from the end of the  group file, cast string to integer
if[ `tail /$etcdir/group  --lines=1|cut -d":" -f3` ]; then
lastgroupid=`tail/$etcdir/group  –lines=1|cut -d”:” -f3`
declare -i lastgroupid
else
#if there  is not a line, set to 999
lastgroupid=999
fi
#if =<999
if[  $lastgroupid -le 999 ]; then
usergroupid=1000
else
#add 1 to  last id
lastgroupid=$lastgroupid+1
#make new id
usergroupid=$lastgroupid
fi
mkdir $homedir/$groupselection
echo “The New User Group has been  created”
#add the new line to group file
echo  $groupselection:x:$usergroupid:>> /$etcdir/group
fi
esac
echo “Would you like to go back to the main menu (y/n) ?”
read  reply
if [ "$reply" = y ]
echo “Back to the main menu…”
./accounts
val=0
fi
#############################################################################################
#Create new user account#
if [ "$reply" = 2 ]; then
clear
echo  “Please enter new users full name and press enter:”
read f_name
#1st  letter of first name
name1=`echo $f_name|cut -c0-1`
#last 7  letters of last name
name2=`echo $f_name|cut -d” ” -f2|cut -c1-7`
#create  username from last 7 letters of last name, 1st letter of first name
username=`echo  $name2$name1 | tr [:upper:] [:lower:]`
num=1
name3=2
#to avoid  creating the same usernames
while [ "$num" = 1 ]; do
if [ `grep  -w $username $etcdir/passwd |cut -d":" -f1` ]; then
#take the 1st  letter if the same name exists
name1=`echo $f_name|cut -c0-1`
#last  6 characters of last name
name2=`echo $f_name|cut -d” ” -f2|cut  -c1-6`
declare -i name3
#add 1 to the end of username
name3=$name3+1
#create  username
username=`echo $name2$name1″$name3″ | tr [:upper:]  [:lower:]`
num=1
else
username=$username
num=0
fi
done
echo  “The new username is: $username…”
#if line present in file use  last existing id from passwd file, cast string to integer
if [ `tail  /$etcdir/passwd --lines=1|cut -d":" -f3` ]; then
lastid=`tail  /$etcdir/passwd –lines=1|cut -d”:” -f3`
declare -i lastid
else
lastid=4999
fi
#if  =<4999
if [ "$lastid" -le 4999 ]; then
#set first id to 5000
userid=5000
else
#add  1 to lastid
lastid=$lastid+1
#create new id
userid=$lastid
echo  “The new user ID is $userid…”
#to create email addresses, insert  a dot in the space between names
aliasfield=`echo $f_name|sed -e ’s/  /./’`
#add to aliases file
`echo $aliasfield:$username >>  /$etcdir/aliases`
echo “Enter password :”
read pass
#encrypt  the password
encrypt=$pass
echo “Current user groups :”
#display  the current user groups
ls -l $homedir|grep “^d”|cut -c 50-80
#prompt  user
echo “Enter the group name you want to add the user to :”
#password  file entry
read groupselection
#lower case letters for group
groupselection=`echo  $groupselection | tr [:upper:] [:lower:]`
num=1
while [ "$num" = 1  ]; do
#if the group is in the group file
if [ `grep -w  $groupselection $etcdir/group |cut -d":" -f1` ]; then
echo “The  ‘$groupselection’ group has been successfully entered…”
num=0
else
echo  “The inputted group $groupselection does not exist, please try again or  press Z to go back to the main menu…”
read groupselection
num=1
elif[  "$groupselection" = z ]
then
#return to the main menu
./accounts
fi
done
#get group id from file
groupid=`grep $groupselection  /$etcdir/group|cut -d”:” -f3`
echo “The group id is $groupid”
#find  the line that the group in question is on
adduserline=`grep $groupid  /$etcdir/group`
#add username to end of groupline
sed -e  “s/$adduserline/$adduserline, $username/g” $etcdir/group >  $etcdir/grouptemp
#delete occurances of “:,”
sed -e “s/:, /:/g”  $etcdir/grouptemp > $etcdir/group
#remove the temporary file
rm  $etcdir/grouptemp
echo “Creating $username directory…”
#set  permissions drwx–x–x
mkdir $homedir/$groupselection/$username -m 711
echo  “Creating $username’s public_html directory…”
#set permissions  drwxr-xr-x
mkdir $homedir/$groupselection/$username/public_html -m  755
#output this entry to the passwd file, this allows it to be  called later
`echo  $username:x:$userid:$groupid:$f_name:$homedir/$groupselection/$username:/bin/bash  >> /$etcdir/passwd`
#output this entry to the shadow file
`echo  $username:$encrypt:0:0:50:7:-1:: >> /$etcdir/shadow`
#only  root can use utilities chown and newaliases
if [ "$USER" = "root" ];  then
#set owner of directory
chown -R $username  $homedir/$groupselection/$username/
newaliases
else
echo  “WARNING - MUST BE ROOT TO RUN THE CHOWN OR NEWALIASES UTILITIES”
fi
fi
fi
esac
echo “Would you like to go back to the main menu (y/n) ?”
read  reply
if [ "$reply" = y ]
echo “Back to the main menu…”
./accounts
val=0
fi
##################################################################################################
#Delete user account#
if [ $reply = 3 ]; then
clear
echo  “The list of all the current system users :”
cat $etcdir/passwd|cut  -d”:” -f1
echo “Choose the username and press enter to delete  their account :”
read del_user
echo “Do you wish to continue  to delete $del_user? (y/n)”
read answer
#read the upper and lower  case characters
answer=`echo $answer | tr [:upper:] [:lower:]`
if [  "$answer" = y ]; then
echo “Currently deleting $del_user from  aliases file…”
cp $etcdir/aliases $etcdir/aliasestemp
sed -e  /:$del_user/d $etcdir/aliasestemp > $etcdir/aliases
#delete from  aliases file
rm $etcdir/aliasestemp
echo “Currently deleting  $del_user from passwd file…”
cp $etcdir/passwd $etcdir/passwdtemp
sed  -e /$del_user:/d $etcdir/passwdtemp > $etcdir/passwd
#delete from  passwd file
rm $etcdir/passwdtemp
echo “Currently deleting  $del_user from shadow file…”
cp $etcdir/shadow $etcdir/shadowtemp
sed  -e /$del_user:/d $etcdir/shadowtemp > $etcdir/shadow
#delete user  from shadow file
rm $etcdir/shadowtemp
echo “Currently  deleting  $del_user’s name from his group…”
mv  $homedir/$groupselection/$del_user $etcdir/grouptemp
rm  $etcdir/grouptemp
#delete from group file
echo “Currently  deleting $del_user from group file…”
cp $etcdir/group  $etcdir/grouptemp
sed -e “s/, $del_user//g” $etcdir/grouptemp >  $etcdir/group
cp $etcdir/group $etcdir/grouptemp
sed -e  “s/$del_user, //g” $etcdir/grouptemp > $etcdir/group
cp  $etcdir/group $etcdir/grouptemp
sed -e “s/$del_user//g”  $etcdir/grouptemp > $etcdir/group
rm $etcdir/grouptemp
echo  “Currently deleting $del_user’s directory…”
#delete users directory
groupselection=`grep  $del_user $etcdir/group|cut -d”:” -f1`
echo “$del_user has been  entirely deleted from the system.”
else
#return to the main menu
./accounts
fi
fi
esac
####################################################################################################
#Create Multiple user accounts from formatted file#
if [ $reply =  4 ]; then
clear
echo “In order to create any users from a  formatted file - it must be named ‘HRfile’ and be placed in the  ‘assign2′ directory”
echo “The following are the contents of this  file :”
#show hrfile
cat $hrfile
echo “Do you wish to  continue adding new users? (y/n)”
read response
response=`echo  $response | tr [:upper:] [:lower:]`
if [ "$response" = n ]; then
echo  “Returing to main menu…”
#return to the main menu
./accounts
else
echo “Currently adding the new users…”
#copy hrfile to temporary  location, edit this file
cp $hrfile $assign2/hrfiletemp
#keep the  firstline line
firstline=`head -n 1  $assign2/hrfiletemp`
#take  this from the file
sed -e /”$firstline”/d $assign2/hrfiletemp >  $assign2/hrfiletemp2
cp $assign2/hrfiletemp2 $assign2/hrfiletemp
#get  the number of lines
lines=`grep “:” $assign2/hrfiletemp -c`
int=0
while  [ $lines -gt $int ]; do
#store a new firstline line
firstline=`head  -n 1  $assign2/hrfiletemp`
#get fullname
f_name=`echo  $firstline|cut -d”:” -f1`
f_name=`echo $f_name | tr [:upper:]  [:lower:]`
#1st letter of first name
name1=`echo $f_name|cut  -c0-1`
#last 7 letters of last name
name2=`echo $f_name|cut -d” ”  -f2|cut -c1-7`
#create username from  last 7 letters of last name,  1st letter of first name
username=`echo $name2$name1 | tr [:upper:]  [:lower:]`
#to avoid creating the same usernames
num=1
name3=2
while  [ "$num" = 1 ]; do
if [ `grep -w $username $etcdir/passwd |cut -d":"  -f1` ]; then
#take the 1st letter if the same name exists
name1=`echo  $f_name|cut -c0-1`
#last 6 characters of last name
name2=`echo  $f_name|cut -d” ” -f2|cut -c1-6`
declare -i name3
#add integer to  end of username
name3=$name3+1
#create the username
username=`echo  $name2$name1″$name3″ | tr [:upper:] [:lower:]`
num=1
else
username=$username
num=0
fi
done
#output end of file
if [ `tail /$etcdir/passwd --lines=1|cut  -d":" -f3` ]; then
#take last existing id from passwd file
lastid=`tail  /$etcdir/passwd –lines=1|cut -d”:” -f3`
#cast string to int
declare  -i lastid
else
lastid=4999
fi
#if <=4999
if [  "$lastid" -le 4999 ]; then
#set first id to 5000
lastid=5000
else
#add  1 to lastid
lastid=$lastid+1
#create new id
userid=$lastid
fi
#to create email addresses, insert a dot in the space between names
aliasfield=`echo  $f_name|sed -e ’s/ /./’`
#add to aliases file
`echo  $aliasfield:$username >> /$etcdir/aliases`
#get the  password
pass=`echo $firstline|cut -d”:” -f2`
#translate the  password
pass=`echo $pass | tr [:upper:] [:lower:]`
#encrypt the  password
encrypt=$pass
#get group
groupselection=`echo  $firstline|cut -d”:” -f3`
groupselection=`echo $groupselection | tr  [:upper:] [:lower:]`
num=1
while [ "$num" = 1 ]; do
#if the  group is in the group file
if [ `grep -w $groupselection  $etcdir/group |cut -d":" -f1` ]; then
num=0
else
echo “The  inputted group $groupselection does not exist, please re-enter group  name…”
read groupselection
num=1
fi
done
#get group  id from file
groupid=`grep $groupselection /$etcdir/group|cut -d”:”  -f3`
echo “The group id is $groupid”
adduserline=`grep  $groupid /$etcdir/group`
#find the line that the group in question is  on
sed -e “s/$adduserline/$adduserline, $username/g” $etcdir/group  > $etcdir/grouptemp
sed -e “s/:, /:/g” $etcdir/grouptemp >  $etcdir/group
rm $etcdir/grouptemp
echo “Creating $username  directory…..”
#set permissions drwx–x–x
mkdir  $homedir/$groupselection/$username -m 711
echo “Creating $username’s  public_html directory……”
#set permissions drwxr-xr-x
mkdir  $homedir/$groupselection/$username/public_html -m 755
#output  entry for new user to passwd file create an entry in the passwd file
`echo   $username:x:$userid:$groupid:$f_name:$homedir/$groupselection/$username:/bin/bash  >> /$etcdir/passwd`
#output entry for new user to shadow  file
`echo $username:$encrypt:0:0:50:7:-1:: >> /$etcdir/shadow`
#limit use of utilities to user root
if [ "$USER" = "root" ];  then
chown -R $username $homedir/$groupselection/$username/
newaliases
else
echo  “WARNING - USER MUST BE ROOT TO USE CHOWN OR NEWALIASES UTILITIES”
fi
sed -e /”$firstline”/d $assign2/hrfiletemp > $assign2/hrfiletemp2
cp  $assign2/hrfiletemp2 $assign2/hrfiletemp
declare -i int
int=$int+1
done
rm  $assign2/hrfiletemp2
rm $assign2/hrfiletemp
fi
fi
esac
echo  “Would you like to go back to the main menu (y/n) ?”
read reply
if  [ "$reply" = y ]
echo “Back to the main menu…”
./accounts
val=0
fi
###############################################################################
#Delete multiple user accounts from formatted file#
if [ $reply =  5 ]; then
clear
echo “To Delete users from file - The file  ‘HRfile’ must exist in the ‘assign2′ directory”
echo “The contents of  this file are shown below:”
#show
cat $hrfile
echo  “Proceed with deleting these users? y/n”
read response
response=`echo  $response | tr [:upper:] [:lower:]`
if [ "$response" = n ]; then
echo  “Returing to main menu…”
./accounts
else
echo “Deleting  users…”
cp $hrfile $assign2/hrfiletemp
firstline=`head -n 1   $assign2/hrfiletemp`
sed -e /”$firstline”/d $assign2/hrfiletemp >  $assign2/hrfiletemp2
cp $assign2/hrfiletemp2 $assign2/hrfiletemp
#get  line count
lines=`grep “:” $assign2/hrfiletemp -c`
int=0
while  [ $lines -gt $int ]; do
firstline=`head -n 1  $assign2/hrfiletemp`
#get full name
f_name=`echo $firstline|cut -d”:” -f1`
f_name=`echo  $f_name | tr [:upper:] [:lower:]`
#enter username in aliases  file, passwd file, group file, shadow file
#take first letter of  first name
name1=`echo $f_name|cut -c0-1`
#take last 7 letters  of last name
name2=`echo $f_name|cut -d” ” -f2|cut -c1-7`
#create  username from the above
username=`echo $name2$name1 | tr [:upper:]  [:lower:]`
echo “Deleting user $username from aliases file…”
cp  $etcdir/aliases $etcdir/aliasestemp
sed -e /:$username/d  $etcdir/aliasestemp > $etcdir/aliases
#Remove user from aliases  file
rm $etcdir/aliasestemp
#remove user from aliases file
echo  “Deleting user $username from passwd file…”
cp $etcdir/passwd  $etcdir/passwdtemp
sed -e /$username:/d $etcdir/passwdtemp >  $etcdir/passwd
#remove user from passwd file
rm $etcdir/passwdtemp
#remove user from passwd file
echo “Deleting user $username from  shadow file…”
cp $etcdir/shadow $etcdir/shadowtemp
sed -e  /$username:/d $etcdir/shadowtemp > $etcdir/shadow
#remove user  from shadow file
rm $etcdir/shadowtemp
#remove username from  shadow file
echo “Deleting user $username’s directory”
groupselection=`echo  $firstline|cut -d”:” -f3`
groupselection=`echo $groupselection | tr  [:upper:] [:lower:]`
rm -r $homedir/$groupselection/$username
#remove  username’s directory
echo “Deleting user $username from group file…”
cp  $etcdir/group $etcdir/grouptemp
#Remove user from group file
sed  -e “s/, $username//g” $etcdir/grouptemp > $etcdir/group
cp  $etcdir/group $etcdir/grouptemp
sed -e “s/$username, //g”  $etcdir/grouptemp > $etcdir/group
cp $etcdir/group  $etcdir/grouptemp
sed -e “s/$username//g” $etcdir/grouptemp >  $etcdir/group
rm $etcdir/grouptemp
echo “User $username’s  account has been removed from the system.”
sed -e /”$firstline”/d  $assign2/hrfiletemp > $assign2/hrfiletemp2
cp $assign2/hrfiletemp2  $assign2/hrfiletemp
declare -i int
int=$int+1
done
rm  $assign2/hrfiletemp2
rm $assign2/hrfiletemp
fi
fi
esac
echo “Would you like to go back to the main menu (y/n) ?”
read  reply
if [ "$reply" = y ]
echo “Back to the main menu…”
./accounts
val=0
fi
#########################################################################################
#Suspend user account#
if [ $reply = 6 ]; then
clear
echo  “The list of the non-suspended system users :”
#add star to the  front of password in shadow file
grep -v ‘*’ $etcdir/shadow|cut -d”:”  -f1
echo “Enter the username to suspend the account :”
read  username
username=`echo $username | tr [:upper:] [:lower:]`
#Search  passwd file for this username
num=1
while [ "$num" = 1 ]; do
#if  you search and find it
if [ `grep -w $username $etcdir/passwd |cut  -d":" -f1` ]; then
echo “Do you wish to continue to suspend  $username’s account (y/n)?”
read reply
reply=`echo $reply | tr  [:upper:] [:lower:]`
if [ "$reply" = n ]; then
#return to the main  menu
./accounts
else
num=0
fi
else
echo  “‘$username’ does not exist, please re-enter username or Z to go back to  the main menu :”
read username
username=$username
username=`echo  $username | tr [:upper:] [:lower:]`
if [ "$username" = z ]; then
#return  to the main menu
./accounts
else
username=$username
fi
fi
fi
done
#search for username, store password
thepass=`grep -w $username  /$etcdir/shadow|cut -d”:” -f2`
#use first letter of password
firstletter=`echo  $thepass|cut -c 0-1`
#Check if this user is already suspended if the  first letter is a *
if [ "$firstletter" = "*" ]; then
echo “The  $username account is already suspended…”
echo “Returning to main  menu…”
./accounts
else
#use 2nd field
cp $etcdir/shadow  $etcdir/shadowtemp
#get the password
thepass=`grep -w $username  /$etcdir/shadowtemp|cut -d”:” -f2`
#sed for 2nd field in file and  replace with *2nd field
sed -e “s/$thepass/*$thepass/g”  $etcdir/shadowtemp > $etcdir/shadow
rm $etcdir/shadowtemp
#change  the user home directory permission t
userhome=`grep $username  /$etcdir/passwd| cut -d”:” -f6`
#no permissions
chmod 000  $userhome
echo “$username’s account is suspended”
fi
echo  “Would you like to go back to the main menu (y/n) ?”
read reply
if  [ "$reply" = y ]
echo “Back to the main menu…”
./accounts
num=0
fi
###################################################################################
#Re-Instate user account#
if [ $reply = 7 ]; then
clear
echo “The list of the currently suspended users on the system :”
#search  shadow file for entries beginning with *
grep ‘*’ $etcdir/shadow|cut  -d”:” -f1
echo “Enter the username to re-instate the account :”
read  username
username=`echo $username | tr [:upper:] [:lower:]`
#search  passwd file for this username
num=1
while [ "$num" = 1 ]; do
#if  you search and find it
if [ `grep -w $username $etcdir/passwd |cut  -d":" -f1` ]; then
echo “Do you wish to continue to re-instate  $username’s account (y/n)?”
read reply
reply=`echo $reply | tr  [:upper:] [:lower:]`
if [ "$reply" = n ]; then
echo “Back to  the main menu…”
./accounts
else
num=0
fi
else
echo  “‘$username’ does not exist, please try again or Z to go back to the  main menu :”
read username
username=`echo $username | tr [:upper:]  [:lower:]`
username=$username
if [ "$username" = z ]; then
echo  “Back to the main menu…”
./accounts
else
username=$username
fi
fi
fi
done
#Check if this user is already suspended if the first letter is a *
thepass=`grep  -w $username /$etcdir/shadow|cut -d”:” -f2`
firstletter=`echo  $thepass|cut -c 0-1`
if [ "$firstletter" = "*" ]; then
#use  2nd field
cp $etcdir/shadow $etcdir/shadowtemp
thepass=`grep -w  $username /$etcdir/shadowtemp|cut -d”:” -f2`
thenewpass=`echo  $thepass|cut -c 2-`

#sed for *2nd field in file and replace with  2nd field
sed -e “s/$thepass/$thenewpass/g” $etcdir/shadowtemp >  $etcdir/shadow
rm $etcdir/shadowtemp

#revert back to the  original home directory permissions
userhome=`grep $username  /$etcdir/passwd| cut -d”:” -f6`
#set permissions drwx–x–x
chmod  711 $userhome
echo “$username’s account has been re-instated”
else
echo  “$username’s account is already active…”
fi
esac
echo  “Would you like to go back to the main menu (y/n) ?”
read reply
if  [ "$reply" = y ]
echo “Back to the main menu…”
./accounts
val=0
fi
###################################################################################
#Make user a member of another group#
if [ $reply = 8 ]; then
clear
echo “Please enter the username of the user :”
read  username
#read the username from upper and lowercase letters
username=`echo  $username | tr [:upper:] [:lower:]`
#search the passwd file for  the username
num=1
while [ "$num" = 1 ]; do
if [ `grep -w  $username $etcdir/passwd |cut -d":" -f1` ]; then
num=0
else
echo  “Username ‘$username’ does not exist, please try again or Z to go back  to the main menu :”
read username
username=$username
if [  "$username" = z ]; then
#return to the main menu
./accounts
else
username=$username
fi
fi
fi
done
echo “The list of the existing groups are :”
#display all  existing groups
ls -l $homedir|grep “^d”|cut -c 50-80
echo “Enter  groupname to add user to”
read groupselection
#search the group  file for the groupname
num=1
while [ "$num" = 1 ]; do
if [  `grep -w $groupselection $etcdir/group |cut -d":" -f1` ]; then
num=0
else
echo  “Group does not exist, please re-enter groupname or Z to go back to the  main menu :”
read groupselection
groupselection=$groupselection
if  [ "$groupselection" = z ]; then
#return to the main menu
./accounts
else
groupselection=$groupselection
fi
fi
done
#if the user already exists and the group already exists
groupline=`grep  -w $groupselection $etcdir/group | cut -d”:” -f4`
if [ `echo  $groupline|grep $username | cut -d"," -f1` ]; then
echo “This user  has already joined this group”
else
echo “Adding user  ‘$username’ to the group ‘$groupselection’”
adduserline=`grep  $groupselection /$etcdir/group`
sed -e “s/$adduserline/$adduserline,  $username/g” $etcdir/group > $etcdir/grouptemp
sed -e “s/:, /:/g”  $etcdir/grouptemp > $etcdir/group
fi
esac
echo  “Would you like to go back to the main menu (y/n) ?”
read reply
if  [ "$reply" = y ]
echo “Back to the main menu…”
./accounts
num=0
fi
##################################################################################
#show home directory space usage for all users#
if [ $reply = 9  ]; then
clear
#show overall disk space usage
t_disk_sp=`du -h|  tail -n 1| cut -c1-3`
echo “Total disk space usage for all users  is : $t_disk_sp”
echo “View individual disk space consumed by  each user? (y/n)”
read individual
individual=`echo $individual |  tr [:upper:] [:lower:]`
if [ "$individual" = y ]; then
echo  “Would you like to display all the users on the system? (y/n)”
read  sys_usr
sys_usr=`echo $sys_usr | tr [:upper:] [:lower:]`
if [  "$sys_usr" = y ]; then
echo “The list of all the system users :”
#show  users
cat $etcdir/passwd| cut -d”:” -f1
fi
echo “Select  the username to view disk space usage :”
read username
#get  user home directory from passwd file
userhome=`grep $username  /$etcdir/passwd| cut -d”:” -f6`
u_disk_sp=`du -h $userhome|tail -n  1|cut -d”/” -f1`
echo “Total disk space usage for user ‘$username’ is  : $u_disk_sp”
else
echo “Back to the main menu…”
./accounts
fi
fi
esac
#####################################################################################
#exit gracefully
if [ "$reply" = 10 ]; then
clear;
echo  “Goodbye and Have a Nice Day :)!!!”
fi
esac
#####################################################################################
#if the user does not enter a number in the range [1-10]
if [  "$reply" = * ]; then
clear
echo “That request cannot be  processed!!!”
#return to the main menu
./accounts
fi
esac
#####################################################################################
esac
exit 0
VN:F [1.8.8_1072]
Rating: 0.0/10 (0 votes cast)
VN:F [1.8.8_1072]
Rating: 0 (from 0 votes)