LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 12-04-2011, 06:00 PM   #1
GhostDZ9
LQ Newbie
 
Registered: Dec 2011
Posts: 1

Rep: Reputation: Disabled
User Management Script - error


Hey guys,

So I am doing a user management script for my linux class and I'm writing a bash script to create users. I have gotten most of it to work so far however I had to put it into a case and switch with a while loop to be able to complete the requirements. I am getting an error with the second case and i don't understand why can someone please help me?

Code:
#!/bin/bash
#Assignment 4 by Rehan Lakhani

#Script interface
#Declaring Variables
leave=no
while [ $leave = no ]
do
clear
cat<<EOF

Welcome to the user management script $USER
1) Create a new user
2) Delete a user
3) Modify a user
4) See last 10 created users
5) Quit
Please enter in a number:
EOF
read selection
case $selection in
	1)
	if [ $selection -eq 1 ]; then
	clear
		if [ $USER == root ]; then
			read -p "Enter username: " username
			read -p "Enter home directory: " homeDir
			read -p "Enter users fullname: " fullName
			read -p "Enter users shell: " uShell
			egrep "^$username" /etc/passwd >/dev/null
			if [ $? -eq 0 ]; then
				echo "$username Exists!"
				continue
			else
				useradd -c "$fullName" -d "$homeDir" -m $username  -s "$uShell"
				passwd $username
				[ $?  -eq 0 ] &&  echo "User has been added to the system!"  || echo "Failed to add user"
				continue
			fi
		else
			echo "Only the root user can add a user to the system"
		fi
	;;
	2)
	if [ $selection -eq 2 ]; then
	clear
		if [ $USER == root ]; then
			read -p "Enter username: " username
			read -p "Do you wish to delete the users home directory [y/n]: " answer
			if [[ $answer == "y" || $answer == "Y" ]]; then
				userdel -r $username
			elif [[ $answer == "n" || $answer == "N" ]]; then
				userdel $username
				echo "Users home directory was not removed"
			fi
		else
			echo "Only the root user can remove a user from the system!"
		fi
	fi
	;;
	3)
	elif [ $selection -eq 3 ]; then
		clear
		echo $testText3
	;;
	4)
	elif [ $selection -eq 4 ]; then
		clear
		echo $testText4
	;;
	5)
	elif [ $selection -eq 5 ]; then
		clear
		leave=yes
	fi
	*)
esac
done
 
Old 12-04-2011, 06:13 PM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
You missed a fi at line 43, immediately before the closing ;; in case 1). I suggest also to re-read your course notes about the case statement. The question is: are the
Code:
if [ $selection -eq 1 ]; then ...
if [ $selection -eq 2 ]; then ...
statements really necessary?
 
  


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
changing home directory permission in user management after user created in suse(KDE) hamedhsn Linux - Security 4 04-06-2011 10:18 PM
Vmware web management user name password error peter5898 Linux - Software 1 07-05-2008 12:03 AM
where to get linux administrator script, ex: script to let's user change user info. hocheetiong Linux - Server 1 03-17-2008 01:06 AM
SAMBA PDC add user script error hitotito Linux - Networking 1 04-22-2005 10:45 PM
bash script problem...or user error? Jalalabee Programming 2 09-10-2003 07:18 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:09 AM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration