LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 08-27-2012, 03:02 PM   #1
slufoot80
Member
 
Registered: Nov 2011
Posts: 69

Rep: Reputation: Disabled
bash shell script error!!! go to "usernameftp=$username"ftp"


This is the error I get

=======================================================
/usr/sbin/adduser: line 95: syntax error near unexpected token `newline'
/usr/sbin/adduser: line 95: ` usernameftp=$username"ftp"'
=======================================================below is the script
=======================================================
#Script to add a user to this Linux system
#!/bin/bash
clear

if [ $(id -u) -eq 0 ]; then

function security
{
chown $username:ftp $sourcedir
chmod 775 $sourcedir
}

function userinfo
{
read -p "Enter User Name : " username

while [ -z $username ]|| egrep "^$username" /etc/passwd 1>/dev/null;
do
echo -ne "Either user exists or you entered a blank, enter username again: ";read -e username
done

echo -ne "Enter your password: ";read -s password

while [ -z $password ];
do
echo -ne "\nEnter your password again: ";read -s -e password
done

echo -ne "\nPlease Enter your User ID Number: ";read -ern5 uid
while [[ ! $uid =~ ^[0-9]+$ ]]||egrep $uid /etc/passwd >/dev/null; do
echo -ne "Please re-enter your uid positive intergers only: ";read -ern5 uid
done

read -p "Enter a Comment : " comment
read -p "Enter Users Source Directory : " sourcedir
while [ ! -d "$sourcedir" ];
do
echo -ne "\n$sourcedir Directory Not Found! Please re-enter: "; read homedir
done
pass=$(perl -e 'print crypt($ARGV[0], "password")' $password) # passing the password entered
}

function shellsel
{
echo ""
echo "Select the type of shell you will be using"
echo""
echo -e "1) Bash Shell - SFTP Secure\n" # Shell selection statement
echo -e "2) False Shell - FTP Unsecure\n"
echo -ne "Enter choice: ";read shell;
case $shell in
1)
shell=/bin/bash # case statment for shell selection.
commentstatic="Internal SFTP Account"
useradd -u $uid -p $pass -c "$comment $commentstatic" -d /forms/$username"sa" -s $shell $username
echo -e "Copying System Files ...."
cd /nas_ftp5/Customer/Troy/T_Skel
cp -Rp `ls` $sourcedir
echo -e "Finished Copying System Files ..."
tail -1 /etc/passwd > $sourcedir/etc/passwd
echo "$username" >> /etc/ftpusers
echo -e "$username" '\t' "$sourcedir" >> /etc/security/chroot.conf
;;
2)
shell=/bin/false
commentstatic="Internal FTP Account"
useradd -u $uid -p $pass -c "$comment $commentstatic" -d /forms/$username"sa" -s $shell $username
echo -e "$username" '\t' "$sourcedir" >> /etc/security/chroot.conf
;;
esac

}

echo -ne "\nIndividual Account or Environment Account\n\n"
echo -e "1) Individual Account\n"
echo -e "2) Environment Account\n"
echo -ne "Enter choice: ";read acctchoice;

case $acctchoice in
1)
userinfo
shellsel
security
;;
2)
userinfo
shellsel
cd /forms
ln -s $sourcedir /forms/$username"sa"
security
echo -ne "Would you like to create a Secondary ftp account? (y/n):"; read -e confirm
case $confirm in
y|Y) echo -ne "\nEnter ftp directory: ";read -e ftpdir
;;
usernameftp=$username"ftp"
useridftp=$userid
let $useridftp++
commentstatic2="Internal Secondary FTP Account"
shell=`egrep $username /etc/passwd| cut -d: -f7`
useradd -u $useridftp -c "$comment $commentstatic2" -d $ftpdir -s $shell $usernameftp
egrep $usernameftp /etc/passwd >> /etc/ftpusers
echo -e "$usernameftp" '\t' "$ftpdir" >> /etc/security/chroot.conf
egrep $usernameftp /etc/passwd >> $ftpdir/etc/passwd
n|N) exit
;;
esac
fi
 
Old 08-27-2012, 03:14 PM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
When appending to variables it is best to encapsulate them with brackets {}.

i.e. instead of:
Code:
usernameftp=$username"ftp"
do:
Code:
usernameftp=${username}ftp
 
Old 08-27-2012, 03:19 PM   #3
slufoot80
Member
 
Registered: Nov 2011
Posts: 69

Original Poster
Rep: Reputation: Disabled
now I get

/usr/sbin/adduser: line 95: syntax error near unexpected token `newline'
/usr/sbin/adduser: line 95: ` usernameftp=${username}ftp'
 
Old 08-27-2012, 03:37 PM   #4
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
You're doing a case. The error is saying it didn't expect a newline because it thought you were still doing the first case test.

Remove the ";;" from below the y|Y) line and add it to the end of the line just above n|N.

Also you should remove the ";;" below the n|N) line as the last line of the case before the esac is the end of the case so doesn't need continuation like earlier steps.

Also it is good practice to have *) condition as last one of a case to make it give an error message if any input other than that expected is given. i.e. What happens if the user types W instead of Y or N? If you did add such an option to your case you WOULD still want the ";;" after the n|N line but not after the new *) line.

Last edited by MensaWater; 08-27-2012 at 03:38 PM.
 
1 members found this post helpful.
Old 08-27-2012, 03:41 PM   #5
robertjinx
Member
 
Registered: Oct 2007
Location: Prague, CZ
Distribution: RedHat / CentOS / Ubuntu / SUSE / Debian
Posts: 749

Rep: Reputation: 73
Should be:

Code:
usernameftp="${username}ftp"
 
Old 08-27-2012, 03:49 PM   #6
slufoot80
Member
 
Registered: Nov 2011
Posts: 69

Original Poster
Rep: Reputation: Disabled
question

how do I write it to accept only y or n or Y or N?
 
Old 08-27-2012, 03:51 PM   #7
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
Quote:
Originally Posted by robertjinx View Post
Should be:

Code:
usernameftp="${username}ftp"
The quotes around the variable aren't required and in some cases can cause confusion. Any way on second look I realized OP's issue is in the case above line 95 rather than line 95 itself. Often error output pukes on unexpected lines rather than the lines that are causing the problem before them.
 
  


Reply

Tags
shell



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 script: using "select" to show multi-word options? (like "option 1"/"o zidane_tribal Programming 7 12-19-2015 01:03 AM
How to set the font-size for "xterm" terminal-emulator (running "bash" shell) ajaygarg Linux - Desktop 1 03-09-2012 12:38 PM
How to stop bash from replacing "~/" with "/home/username"? daihard Linux - Software 8 08-22-2010 02:32 PM
Shell script: I have string "abc____def____ghi", how to make "abc def ghi" vouser Programming 8 03-09-2010 10:01 PM
Why "bash-2.05b$" in Terminal instead of "username@localhost username" jayelitumbiolo Linux - General 9 10-04-2009 03:16 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

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