The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
passing variable from bash to perl from bash script arsidh Shell Programming and Scripting 10 06-04-2008 09:25 AM
How do i change to super user then revert back to ordinary user ,using shell script? wrapster Shell Programming and Scripting 3 06-04-2008 04:11 AM
Why generate "ash and bash" different output for same bash script? s. murat Shell Programming and Scripting 0 05-26-2008 04:19 AM
Problem setting up Bash user account sumanroyc UNIX for Advanced & Expert Users 2 10-27-2006 02:57 PM
Help with Flat Files Please!! BASH (New User) cyberjax21 Shell Programming and Scripting 0 02-27-2006 06:19 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 05-10-2008
Registered User
 

Join Date: May 2008
Posts: 3
Bash - Add User script

Hey folks! I'm trying to work on a script that will add a user to the system. I have the complete script, but it's not working for me, and I'm not sure what to do.

line 53: syntax error near unexpected token `0'

********************************************************

Code:
#!/bin/bash
#
#  complete add user script
#
initialize_variables ()
{
noinput=
user_id=' '
user_id_num=' '
home_directory=' '
group_id_num=' '
group_name=' '
#
#
cat /u/reedk/ulist|cut -f3 -d':'|sort -bg > luid_file
#
tuid=$(tail -1 luid_file)
let user_id_num=$tuid+1
echo "$user_id_num"
}
#
display_heading ()
{
clear
echo "           ADD USER SCREEN        "
echo " _________________________________"
}
main_menu ()
{
   let doption=100
   while [ $doption != 99 ]
    do
     display_heading


echo "  1.  Enter user real name .................. $user_name       "
echo "      Next available user ID Number ......... $user_id_num     "
echo "  2.  Enter Group ID Number ................. $group_id_num    "
echo "                Group name .....$group_name"
echo "  3.  Enter Home Directory  ................. $home_directory  "
echo "  4.  Enter Default Shell  .................. $default_shell   "
echo " "
echo " user_add -c "$user_name" -d $home_directory -g $group_id_num -G $group_name -m -s $default_shell $strt_script "
echo " "
echo "  0.  ADD USER NOW  "
echo " "
echo " "
echo "  99.  EXIT   (Take no action)  "
echo " ============================================================"
echo " Please select an option ===>   "
read option
case $option in
  0)  echo " user_add -c "$user_name" -d $home_directory -g $group_id_num -G $group_name -m -s $default_shell $strt_script "
      echo " $user_name has been added successfully"
      sleep 5
     ;;
  1)  display_heading
      echo "Please the users real name: (fi.mi.last)  ==>  "
      read confirm_reply
      if [ "$confirm_reply" = "$noinput" ]
         then
           echo " No user name entered"
         else
           user_name=$confirm_reply
           home_directory=/u/$user_name
           default_shell=/bin/bash
           if [ "$user_name" = "$( cat /u/reedk/ulist|cut -f1 -d':'|grep $user_name) " ]
             then
              echo " User name already exists"
           fi
      fi
      ;;
  2)  display_heading
      echo "Enter the primary Group ID Number ==>  "
      read confirm_reply
      group_name=' '
      if [ "$confirm_reply" = "$noinput" ]
        then
         echo "No primary group ID was entered"
        else
         grpfnd='n'
         group_id_num=$confirm_reply
         for i in $(cat /u/reedk/gfile|cut -f1,3 -d':')
          do
            if [ $(echo $i|cut -f2 -d':') -eq $group_id_num ]
             then
               grpfnd='y'
               group_name=$(echo $i|cut -f1 -d':')
            fi
            done
            if [ $grpfnd = 'n' ] || [ $group_id_num -eq 0 ]
              then
               echo "Invalid primary group number entered"
            fi
      fi
      ;;
  99)  let doption=99
       ;;
esac
done
}
#
###################################
#  BEGIN MAIN PROGRAM             #
###################################
if [ "$(whoami)" != "$( cat /u/reedk/auth.list|grep $(whoami) )" ]
   then
     echo " You are not authorized to run this script ... Contact your System Administrator "
   else
     initialize_variables
     main_menu
fi
Reply With Quote
Forum Sponsor
  #2  
Old 05-10-2008
Registered User
 

Join Date: May 2008
Posts: 3
text in red is line 53
Reply With Quote
  #3  
Old 05-10-2008
drl's Avatar
drl drl is online now
Registered User
 

Join Date: Apr 2007
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 554
Hi.

How many quotes do you count? ... cheers, drl
Reply With Quote
  #4  
Old 05-10-2008
Registered User
 

Join Date: May 2008
Posts: 3
I'm not sure what you mean. On line 53 I have 4 double quotes (")
-2 open / 2 close

The error message states:

line 53: syntax error near unexpected token `0'

But if you look at my actual code, there is no single quote next to the 0)

/Confusion

EDIT:
I should add.. I'm pretty new to scripting and UNIX in general. I have some know how of programming in C+, but a few drinks in me know.. so I may just be not seeing what you tried to tell me.

Last edited by niels.intl; 05-10-2008 at 05:30 PM.
Reply With Quote
  #5  
Old 05-10-2008
drl's Avatar
drl drl is online now
Registered User
 

Join Date: Apr 2007
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 554
Hi.

Yes, you are correct. I did not see all the way to the end of line 53. I apologize.

One debugging tool is:
Code:
set -x
placed near the beginning of the script. It will cause every command to be listed as it is executed, letting you see what bash sees. The error will then often be apparent.

I extracted a segment of your script at the beginning of the case and it ran without error, so the problem is likely before that.

If you cannot see the error, post a small portion of the "-x" output just before and including the error message ... cheers, drl
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 12:09 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0