LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-29-2005, 07:54 AM   #1
Spyiish
Member
 
Registered: Aug 2004
Location: Australia, Melbourne
Distribution: Slackware 10
Posts: 105

Rep: Reputation: 15
Bash Programming (Create a Menu)


Hi linux programmers,

I was wondering if one of u wud be nice enough to tell me the code of reating "add users, delete users".

Add user must include a file netusers.txt which must be read through this file. It shud create users in linux and in samba.

Delete user shud read the file to delete. For each user ask whether the files are to be deleted, or are to remain on the server. Delete the user, and depending on the response to the prompt, delete the user directory or not.

Thanks
 
Old 03-29-2005, 08:50 AM   #2
TheLinuxDuck
Member
 
Registered: Sep 2002
Location: Tulsa, OK
Distribution: Slack, baby!
Posts: 349

Rep: Reputation: 33
Why don't you post your code so far, and where you're having troubles, and then we'll see if we can help.
 
Old 03-30-2005, 12:04 AM   #3
Spyiish
Member
 
Registered: Aug 2004
Location: Australia, Melbourne
Distribution: Slackware 10
Posts: 105

Original Poster
Rep: Reputation: 15
This is code now.. I cant get the add user working...


function Add_users()

{
clear
echo "Add users selected"
echo
echo
echo " Add users menu"
echo " *****************************"
echo " 1. Add users from file"
echo " 2. Add user manually"
echo " 3. Exit to main menu"
echo " *****************************"
echo "please enter the number of ur choice (1-3)"
read Add_choice

case $Add_choice in


1)
Add_user_from_file
;;
2)
Add_user_manually
;;
3)
clear
Main_Menu_function
;;
esac

}

function Add_user_manually
{
echo -n "Enter first name: "
read First_name

echo -n "enter last name: "
read Last_name

echo -n "enter group name: "
read Group_name

echo -n "enter year of enrollment: "
read year

echo -n "enter password (must not be based on a dictionary word): "
read password

echo -n "enter username: "
read username


if [ ! -d /home/$year ]
then
mkdir /home/$year/
echo "creating /home/$year"
else
echo "folder /home/$year already exists."
fi


if [ ! -d /home/$year/$Group_name ]
then
mkdir /home/$year/$Group_name
echo "creating /home/$year/$Group_name"
else
echo " /home/$year/$Group_name directory already exists"
fi



if [ ! -d /home/$year/$Group_name/$username ]
then
mkdir /home/$year/$Group_name/$username
echo "creating /home/$year/$Group_name/$username"
else

echo "/home/$year/$Group_name/$username directory already exists"
fi





/usr/sbin/useradd -c "$firstname,$Group_name" -d "/home/$year/$Group_name/$username" $username

## useradd -g $Group_name -s /bin/shell -d /home/$year/$Group_name/$username -m $username -c $First_name$Last_name 2>> file1.txt

echo $password | /usr/bin/passwd --stdin $username


#mkdir /home/$Year/$Group/$username/public_html 2>> file1.txt
#echo "users created"


}



Thanks
 
Old 03-30-2005, 01:55 AM   #4
zeropash
Member
 
Registered: Apr 2003
Location: Bangalore,India
Distribution: FC2, RHES, RH9, FC3, FC1, Slackware 3.0
Posts: 208

Rep: Reputation: 30
you are reading the name into the variable First_name etc
but you use firstname which is not initialized
make sure that you use the variables consistantly.
Also why do you create directories for groups etc.
And if the directory already exists then if you use them then there is a problem.
 
Old 03-31-2005, 11:57 AM   #5
jonaskoelker
Senior Member
 
Registered: Jul 2004
Location: Denmark
Distribution: Ubuntu, Debian
Posts: 1,524

Rep: Reputation: 47
tip: "help select"
Code:
add="add user"
del="delete user"
quit="exit to main menu"
select what in "$add" "$del" "$quit"; do
  case $what in
    $add) add_fun () ;;
    $del) del_fun () ;;
    $quit) quit_fun () ;;
  esac
done
 
Old 04-01-2005, 03:45 AM   #6
Spyiish
Member
 
Registered: Aug 2004
Location: Australia, Melbourne
Distribution: Slackware 10
Posts: 105

Original Poster
Rep: Reputation: 15
Cheers,

I'll redo again, and show u my code later....

Thanks
 
  


Reply



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
Create new from context menu johnnydangerous Fedora 3 02-07-2005 04:29 PM
bash programming drisay Programming 6 12-20-2004 09:09 AM
Can't create new menu folder with Nautilus markelo Linux - Software 1 09-29-2004 09:43 AM
bash programming cpukiller Linux - Newbie 1 11-04-2003 06:45 PM
bash programming bulliver Programming 2 04-05-2003 09:30 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:48 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
Open Source Consulting | Domain Registration