LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This 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


Reply
  Search this Thread
Old 07-23-2006, 06:27 AM   #1
drum2jc
Member
 
Registered: Aug 2004
Location: Arroyo Grande, Ca
Distribution: Ubuntu 6.06
Posts: 49

Rep: Reputation: 15
bash scripting


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

thanks a bunch,
chris
 
Old 07-23-2006, 07:21 AM   #2
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
You could try #!/bin/bash -x so you can see what's happening.

This method of adding a user and password does seem to work but, I use a slightly different method.
Code:
  adduser $name<<PASS
  echo $pass1
  echo $pass2
  PASS
Code:
adduser ${NAME} -g ${NAME}
    (echo ${PASS1}; echo ${PASS2}) | passwd --stdin ${NAME} > /dev/null
Code:
#!/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

Last edited by homey; 07-23-2006 at 07:55 AM.
 
Old 07-23-2006, 07:35 AM   #3
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
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
 
Old 07-23-2006, 07:41 AM   #4
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
one more thing i kinda doubt this will work:

Code:
  adduser $name<<PASS
  echo $pass1
  echo $pass2
PASS
why not do this instead?

Code:
echo -e "$pass1\n$pass2" | adduser $name
 
Old 07-23-2006, 04:33 PM   #5
spooon
Senior Member
 
Registered: Aug 2005
Posts: 1,755

Rep: Reputation: 51
this is kind of stupid
Code:
  adduser $name<<PASS
  echo $pass1
  echo $pass2
PASS
it will print out
Code:
  echo password
  echo password
including the word echo and two leading spaces

should be
Code:
  adduser $name<<PASS
$pass1
$pass2
PASS
 
Old 07-23-2006, 05:57 PM   #6
fotoguy
Senior Member
 
Registered: Mar 2003
Location: Brisbane Queensland Australia
Distribution: Custom Debian Live ISO's
Posts: 1,290

Rep: Reputation: 62
Code:
    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.
 
Old 07-23-2006, 06:31 PM   #7
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
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
 
Old 07-24-2006, 12:47 AM   #8
fotoguy
Senior Member
 
Registered: Mar 2003
Location: Brisbane Queensland Australia
Distribution: Custom Debian Live ISO's
Posts: 1,290

Rep: Reputation: 62
Quote:
Originally Posted by homey
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Bash Scripting paranoid times Programming 4 02-15-2006 10:48 AM
bash scripting vadon Linux - Newbie 6 05-10-2005 04:07 AM
Bash scripting Gunslinger_ROL Programming 5 09-28-2004 11:37 AM
Bash Scripting Help Aioth Linux - Newbie 8 09-21-2004 11:21 AM
About bash scripting pazvant Programming 3 10-20-2003 11:12 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:03 PM.

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