bash shell script error!!! go to "usernameftp=$username"ftp"
Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
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.
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
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.