Sponsored Content
Full Discussion: Bash - Add User script
Top Forums Shell Programming and Scripting Bash - Add User script Post 302193693 by niels.intl on Saturday 10th of May 2008 04:51:03 PM
Old 05-10-2008
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

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash Script verify user input is not empty and is equal to a value

I need to create a script that has a user enter a value. I want to verify that the value is either 1,2, or 3. If it is not then I want them to try entering it again. I am using a while loop to force them to retry. I am able to test the input against 1,2, and 3, but when I test agains an... (4 Replies)
Discussion started by: spartiati
4 Replies

2. Homework & Coursework Questions

brand new user!.. Lost on BASH script writing

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I have just gotten into writing bash scripts for a class, part of the assignment is to read and be able to tell... (4 Replies)
Discussion started by: Byrang
4 Replies

3. Shell Programming and Scripting

Need to run a bash script that logs on as a non-root user and runs script as root

So I have a script that runs as a non-root user, lets say the username is 'xymon' . This script needs to log on to a remote system as a non-root user also and call up a bash script that runs another bash script as root. in short: user xymon on system A needs to run a file as root user and have... (2 Replies)
Discussion started by: damang111
2 Replies

4. UNIX for Advanced & Expert Users

how to add new options in bash script

what i want to be is that i would like to reinvent new options that have the same functionality as ... -u is the same functionality of conv=ucase and -l have the same functionality as conv=lcase... is there a way that i can put these in my script so that whenever i will typed in command... (12 Replies)
Discussion started by: aphryllyn1
12 Replies

5. Shell Programming and Scripting

Bash shell script for user creation in solaris

Hi All, I am new to shell scripting and have a task which need to be completed ASAP. I have searched all the forum and couln't find excat script which could run on solaris.can someone give me the fully working script for below. Bash shell script to create user account with paraments as... (1 Reply)
Discussion started by: sintilash
1 Replies

6. Shell Programming and Scripting

How to write bash script for creating user on multiple Linux hosts?

I wonder whether someone can help me with what I'm trying to achieve Basically, the objective is one script to create new user on more than 70 linux hosts if required. Everything works apart from the highlighted part. It gave me an output passwd: Unknown user name ''. when try to set... (35 Replies)
Discussion started by: fugeulu
35 Replies

7. Ubuntu

Exit user in bash script

I'm writing a bunch of scripts to automatically configure Ubuntu and I want to run the code below to remove the white dots from the login screen: sudo xhost +SI:localuser:lightdm sudo su lightdm -s /bin/bash gsettings set com.canonical.unity-greeter draw-grid false The problem is that... (3 Replies)
Discussion started by: maerlyngb
3 Replies

8. Shell Programming and Scripting

Bash Question: HowTo Exit Script with User Input While Process is Running Mid-Loop?

Hi, I have written a script that allows me to repetitively play a music file $N times, which is specified through user input. However, if I want to exit the script before it has finished looping $N times, if I use CTRL+c, I have to CTRL+c however many times are left in order to complete the loop.... (9 Replies)
Discussion started by: hilltop_yodeler
9 Replies

9. Homework & Coursework Questions

Bash Script for Dice Game; Issue with if...else loop to verify user guess is within range

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I have written a script for a dice game that: (1) tells user that each of the 2 die are 6 sided (Spots=6); (2)... (3 Replies)
Discussion started by: LaurenRose
3 Replies

10. Shell Programming and Scripting

Curl , download file with user:pass in bash script

Hello, My question is about curl command. (ubuntu14.04) In terminal, I am able to download my mainfile with: curl -u user1:pass1 http://11.22.33.44/******* When I convert it into bash script like this: #!/bin/bash cd /root/scripts computer_ip=11.22.33.44 curl -u $1:$2... (8 Replies)
Discussion started by: baris35
8 Replies
script(1)						      General Commands Manual							 script(1)

NAME
script - Makes a transcript of terminal session SYNOPSIS
script [-a] [file] The script command makes a transcript of everything printed on your terminal. OPTIONS
Appends the transcript to file rather than writing it to file. OPERANDS
The name of an output file that will contain the transcript of the session. If this parameter is omitted, the file typescript is written. DESCRIPTION
The transcript is written to file, or appended to file if the -a option is given. If no file name is given, the transcript is saved in the file typescript. The script ends when the forked shell exits. This program is useful when you are using a CRT and want a hard-copy record of the dialog (for example, a technical writer might create an example of a working session this way). If you specify the -a option and the file does not exist, it is created. If you do not specify the -a option and the file exists, it is replaced. RESTRICTIONS
The script command requires a streams based terminal. In single user mode, streams may not be enabled. Under these circumstances, script will exit with no action. If you are the superuser and need to run this command in single user mode, use the following special instruc- tions. Enabling Streams If it is necessary to enable a streams environment in the single user mode, enter the command /sbin/init.d/streams. This command is avail- able to the superuser only. SEE ALSO
Commands: autopush(8), cat(1), echo(1), strsetup(8), tee(1) System Administration script(1)
All times are GMT -4. The time now is 08:31 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy