shell script at bottom of script - what am I missing
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's 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.
shell script at bottom of script - what am I missing
Below is the error I get when I run the program
=======================================================
/usr/sbin/adduser: line 111: syntax error near unexpected token `)'
/usr/sbin/adduser: line 111: ` n|N) exit'
=======================================================
Below this is a copy of my program
=======================================================
#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
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
while [ ! -d "$ftpdir" ];
do
echo -ne "\n$ftpdir Directory Not Found! Please re-enter: "; read ftpdir
done
script fails at: " echo -ne "Would you like to create"
the script exit's when asked the question to create secondary account around line 92, and doesn't read the rest of the file.
==================================================================================================== ============================================
#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
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
while [ ! -d "$ftpdir" ];
do
echo -ne "\n$ftpdir Directory Not Found! Please re-enter: "; read ftpdir
done
Below is where my script fails it works until it get to this point, when I hit the case statement it fails why
==================================================================================================== ============================================
Would you like to create a Secondary ftp account? (y/n):y
Please answer yes or no.
==================================================================================================== ============================================
here is the code
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
while [ ! -d "$ftpdir" ];
do
echo -ne "\n$ftpdir Directory Not Found! Please re-enter: "; read ftpdir
done
no, you have got another error message. Probably similar, but surely not the same. At this moment you have ;; on line 97 (the line before the error message), and that causes this error. that ;; line should not be there.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.