Linux - GeneralThis 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
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.
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
#}
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. "
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.