ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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)
Distribution: Redhat Linux 8 & 9, Fedora Core 2, XP
Posts: 301
Original Poster
Rep:
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?
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.