LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 02-06-2005, 11:06 AM   #1
dx0r515t
Member
 
Registered: Jan 2005
Location: USA
Distribution: Slackware 10.2 & 11.0
Posts: 155

Rep: Reputation: 30
script help


I’m having a problem with a script I wrote to help me make users and link something’s real quick. It works well under Red Hat and Suse, but I moved to Ubuntu (Debian-based) and now I have two problems. First off, I try to check for root user but that seems to be over looked completely. It just kicks straight into the rest of the script. The second problem is that in Red Hat and Suse have the smbadduser command to add samba users. Well, Ubuntu doesn’t. Is there a way I can use some-sort of append command? Cat seems to want files, not phrases. Here’s the script for you who wanna see it.

#!/bin/sh
cd /

if [`id -u` != 0]; then
echo "You must be root to run this script"
exit 1
else
clear
echo -n "Enter the user name you wish to work with > "
read user
clear

function user_exist
{
if grep $user /etc/passwd; then
echo "$user HAS AN ACCOUNT ALREADY"
else
echo "$user DOES NOT EXIST"
echo -n "Would you like to create the user > "
read choice
if [ "$choice" = "y" ]; then
useradd -m -p password $user
echo "$user HAS BEEN CREATED"
else
echo "$user HAS BEEN IGNORED"
fi
fi
}

function home_dir
{
if [ -d /home/$user/ ]; then
echo "$user HAS A HOME DIRECTORY"
else
echo "$user DOES NOT HAVE A HOME DIRECTORY"
fi
}

function web_dir
{
if [ -L /home/$user/public_html ]; then
echo "$user HAS A LINKED WEB DIRECTORY"
else
echo "$user DOES NOT HAVE A WEB DIRECTORY"
echo -n "Would you like $user to have a web directory > "
read wchoice
if [ "$wchoice" = "y" ]; then
ln -s /srv/www/htdocs/$user /home/$user/public_html
echo "$user NOW HAS A WEB DIRECTORY"
else
echo "$user WILL NOT HAVE A WEB DIRECTORY"
fi
fi
}

function smb_user
{
if grep $user /etc/samba/smbpasswd; then
echo "$user HAS SAMBA ACCESS"
else
echo "$user DOES NOT HAVE SAMBA ACCESS"
echo -n "Do you want to allow Samba to this user > "
read smbans
if [ "$smbans" = "y" ]; then
smbadduser $user:$user
echo "$user WAS ADDED TO THE SAMBA SYSTEM"
else
echo "$user WAS NOT GIVEN SAMBA ACCESS"
fi
fi
}

function change_user
{
echo -n "You wish to change users to > "
read user
}

function user_rem
{
echo "THIS WILL DELETE $user FROM THE SYSTEM!!"
echo -n "ARE YOU SURE YOU WANT TO DO THIS > "
read remchoice
if [ "$remchoice" = "y" ]; then
userdel -r $user
echo "$user HAS BEEN PURGED FROM THE SYSTEM"
else
echo "$user WAS NOT DELETED"
fi
}

#function chng_pwd
#{
#echo -n "WOULD YOU LIKE TO CHANGE $user PASSWORD > "
#read pwdchoice
#if [ "$pwdchoice" = "y" ]; then
# passwd $user
#}

until [ "$selection" = "0" ]; do
echo ""
echo "Makeuser Menu"
echo ""
echo "1 - Verify Username"
echo "2 - Verify Home Directory"
echo "3 - Verify Web Directory"
echo "4 - Verify Samba Status"
echo "5 - Change User"
echo "6 - Remove User"
echo ""
echo "0 - Exit"
echo ""
echo -n "Enter Selection: "
read selection
echo ""
case $selection in
1 ) user_exist ;;
2 ) home_dir ;;
3 ) web_dir ;;
4 ) smb_user ;;
5 ) change_user ;;
6 ) user_rem ;;
0 ) clear; exit ;;
* ) echo "Please choose a valid option"
esac
done
fi
 
Old 02-06-2005, 11:23 AM   #2
jailbait
LQ Guru
 
Registered: Feb 2003
Location: Virginia, USA
Distribution: Debian 12
Posts: 8,337

Rep: Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548
The problem with id -u may be that it is always returning an error code like "program not found". You might be able to finesse the problem with
if [`id -u` != 0];
by substituting the equivalent command
if test "`whoami`" != "root";

"The second problem is that in Red Hat and Suse have the smbadduser command to add samba users. Well, Ubuntu doesn’t. "

It might be called smbpasswd.

---------------------------
Steve Stites
 
Old 02-07-2005, 12:35 AM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
when comparing numbers, use
-eq, -ne -gt, -lt
comparing strings
=, !=, >, <

Also, using 2 sets of square brackets, it's safer ie
if [[ $! -ne 0 ]]
then
whatever
fi

Your 'unless' statement is assigning zero, not comparing it....
HTH
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Iptables (with masq) troubleshooting, very simple script attached script and logs. xinu Linux - Networking 13 11-01-2007 04:19 AM
Directory listing - Calling shell script from a CGI script seran Programming 6 08-11-2005 11:08 PM
creating shell script that executes as root regardless of who runs the script? m3kgt Linux - General 13 06-04-2004 10:23 PM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 12:20 AM
linux 9 and java script error - premature end of script header sibil Linux - Newbie 0 01-06-2004 04:21 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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