Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
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.
can someone tell me what i'm doing wring? i get an error: "line 35: syntax error: unexpected end of file"
Code:
#!/bin/bash
homedir=/home/$name/public_html
echo -e "\033[31m Enter the user you want to add to the system, ftp and webserver: \033[0m"
echo "Username:"
read name
echo "Password:"
read -s pass1
echo "Confirm Password:"
read -s pass2
pagehtml="<h1>Index page for $name</h1><h5>You should add some content to your public_html directory!</h5>"
if ["$pass1" = "$pass2"]; then
echo "Passwords match... adding user to system."
adduser $name<<PASS
echo $pass1
echo $pass2
PASS
mkdir $homedir
chown $name $homedir
chmod 755 $homedir
echo $pagehtml > $homedir/index.php
echo -e "\033[31m Webserver directory was created. \033[0m"
echo -e "\033[31m $name was added to the system(ftp and webserver) \033[0m"
exit 0
else
echo "Passwords did not match. Please run the script again."
exit 0
fi
#!/bin/bash
echo -e "\033[31m Enter the user you want to add to the system, ftp and webserver: \033[0m"
read -p "UserNAME:" NAME
read -p "Password:" PASS1
read -p "Confirm Password:" PASS2
pagehtml="<h1>Index page for $NAME</h1><h5>You should add some content to your public_html directory!</h5>"
if [ "$PASS1" = "$PASS2" ]; then
echo "Passwords match... adding user to system."
groupadd ${NAME} 2> /dev/null ##Change this if user needs a different group
adduser ${NAME} -g ${NAME}
(echo ${PASS1}; echo ${PASS2}) | passwd --stdin ${NAME} > /dev/null
echo -n "Added linux user ${NAME}, "
mkdir -p /home/$NAME/public_html
homedir=/home/$NAME/public_html
chown $NAME $homedir
chmod 755 $homedir
echo $pagehtml > $homedir/index.php
echo -e "\033[31m Webserver directory was created. \033[0m"
echo -e "\033[31m $NAME was added to the system(ftp and webserver) \033[0m"
exit 0
else
echo "Passwords did not match. Please run the script again."
exit 0
fi
next time don't add whtie spaces to your "<<PASS ... PASS"
this should fix it:
Code:
#!/bin/bash
homedir=/home/$name/public_html
echo -e "\033[31m Enter the user you want to add to the system, ftp and webserver: \033[0m"
echo "Username:"
read name
echo "Password:"
read -s pass1
echo "Confirm Password:"
read -s pass2
pagehtml="<h1>Index page for $name</h1><h5>You should add some content to your public_html directory!</h5>"
if ["$pass1" = "$pass2"]; then
echo "Passwords match... adding user to system."
adduser $name<<PASS
echo $pass1
echo $pass2
PASS
mkdir $homedir
chown $name $homedir
chmod 755 $homedir
echo $pagehtml > $homedir/index.php
echo -e "\033[31m Webserver directory was created. \033[0m"
echo -e "\033[31m $name was added to the system(ftp and webserver) \033[0m"
exit 0
else
echo "Passwords did not match. Please run the script again."
exit 0
fi
groupadd ${NAME} 2> /dev/null ##Change this if user needs a different group
adduser ${NAME} -g ${NAME}
(echo ${PASS1}; echo ${PASS2}) | passwd --stdin ${NAME} > /dev/null
echo -n "Added linux user ${NAME}, "
mkdir -p /home/$NAME/public_html
homedir=/home/$NAME/public_html
chown $NAME $homedir
chmod 755 $homedir
Maybe cut down on a bit of code try something like this
Code:
groupadd ${NAME} 2> /dev/null ##Change this if user needs a different group
mkdir -p /home/$NAME/public_html
useradd ${NAME} -g ${NAME} -s /bin/sh -d /home/${NAME}/public_html -m -k /etc/skel
echo ${NAME}:${PASS1} | chpasswd
Then just place the index.php in the /etc/skel directory and when the user is created it will automatically copy all files in the /etc/skel directory to the users home directory and adjust all permissions to suit.
Nice tip fotoguy!
Actually Fedora automatically creates the /home/username folder, grabs input from /etc/skel and adds the user to a group of same name as user.
So, I guess it could be cut down more for my FC5 boxen.
Code:
useradd ${NAME}
echo ${NAME}:${PASS1} | chpasswd
echo -n "Added linux user ${NAME}, "
mkdir -p /home/$NAME/public_html
Nice tip fotoguy!
Actually Fedora automatically creates the /home/username folder, grabs input from /etc/skel and adds the user to a group of same name as user.
Thanks! Yeah most distros do, I know slackware doesn't automatically create the users home directory if you use the useradd by the command line unless you include the -m -k /etc/skel with it.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.