LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 05-30-2004, 03:24 AM   #16
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872

Well do no hesitate to put the script here, frankly I don't see what's wrong if $group_name entered by user (although if the user has no rights to write in /home, it is logical than it can't create directory here)
 
Old 05-31-2004, 12:02 AM   #17
kenji1903
Member
 
Registered: Apr 2004
Location: M'sia, Aus, Chn
Distribution: Redhat Linux 8 & 9, Fedora Core 2, XP
Posts: 301

Original Poster
Rep: Reputation: 30
Here is part of the code, have not finished it off yet.
I know it looks like what a elementary school student would have written, I am just a bad programmer

Code:
#!/bin/bash

echo "*************************"
echo "* Please select an option:       *"
echo "* 1. Create a group                 *"
echo "* 2. Adding a user                    *"
echo "* 3. Adding a machine account *"
echo "* OR Press any key to exit        *"
echo "**************************"

read menu_input

case $menu_input in 
1)  echo "===== Group creation ====="
    echo -n "Please enter group name: "
    read group_name

    group_test=$(cat /etc/group | awk -F: '{ print $1 }' | grep $group_name)

    if [ -z $group_test ] || [ ! "$group_test" = "$group_name" ]; then
	/usr/sbin/groupadd "$group_name"
	mkdir /home/"$groupname"
	chgrp "$groupname" /home/"$groupname"
	chmod 0770 /home/"$groupname"
	echo "Group and Group's home directory added"
    else 
	echo "Group already exists! Skipping group creation..."
    fi
;;
2) echo "Adding a user"
;;
3) echo "Adding a machine account"
;;
*) echo "Exit"
esac
I was reading other threads about scripts... those mkdir, chown commands, do they belong somewhere like /usr/bin or /sbin? Maybe i need to include the entire path of the command or something, do I?
 
Old 05-31-2004, 04:43 AM   #18
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
replace the lines
Code:
mkdir /home/"$groupname"
chgrp "$groupname" /home/"$groupname"
chmod 0770 /home/"$groupname"
by :
Code:
mkdir /home/$group_name
chgrp $group_name /home/$group_name
chmod 0770 /home/$group_name

Last edited by keefaz; 05-31-2004 at 04:44 AM.
 
Old 05-31-2004, 07:56 AM   #19
Ma3oiS
LQ Newbie
 
Registered: May 2004
Posts: 12

Rep: Reputation: 0
Hi,

I think you can't create directory with mkdir because you've already created it... check your /home/ directory.
If you don't want mkdir to display error messages replace it with
mkdir "/home/$group_name" &> /dev/null

Ma3oiS
 
Old 05-31-2004, 10:11 AM   #20
kenji1903
Member
 
Registered: Apr 2004
Location: M'sia, Aus, Chn
Distribution: Redhat Linux 8 & 9, Fedora Core 2, XP
Posts: 301

Original Poster
Rep: Reputation: 30
thanks guys, i'll give that a try first thing tomorrow morning
Cracking my head in the mean time on RAID stuff, haha

CheeRs,
~WiLL~
 
Old 06-03-2004, 10:14 PM   #21
kenji1903
Member
 
Registered: Apr 2004
Location: M'sia, Aus, Chn
Distribution: Redhat Linux 8 & 9, Fedora Core 2, XP
Posts: 301

Original Poster
Rep: Reputation: 30
Thanks guys~

Its working now
I'll come back if I have more queries (I bet that will me very soon, haha)

CheeRs,
~WiLL~
 
  


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
viewing, adding(to), deleting(from) groups chibi Linux - Newbie 6 10-16-2005 08:38 PM
Adding more groups to files djchris Linux - Security 1 07-27-2005 10:36 AM
Simple groups question scottrell Linux - General 1 12-02-2004 03:35 PM
Adding user and groups manon Linux - Newbie 3 04-26-2004 12:14 PM
Adding secondary groups thepurpleblob Linux - General 1 09-03-2003 10:19 AM

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

All times are GMT -5. The time now is 02:06 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