Home Page
F-Zero Central Community Update (Jul.) Championships General Forum Players Photo Album
F-Zero Climax
F-Zero GP Legend
F-Zero MV
F-Zero X
F-Zero GX
F-Zero SNES
F-Zero Climax F-Zero GP Legend F-Zero MV F-Zero X F-Zero GX F-Zero SNES
Twitter Facebook YouTube Twitch
   « View previous topic | View next topic »  
    Index » MFO Software Development » Bash Scripting
EnjoiNY
Black Bull
Posts: 314
View user's profile
Send private message
Bash Scripting
Reply to this Post

Can anyone help me with some basic Unix scripting in the bash shell? I'm trying to make several scripts to combine into a function that will add a user to the system. I'm not asking for anyone to write the scripts... just maybe browsing over some of my code and constructively criticizing the balls off me.

badbigwlly
Fat Shark
Posts: 1171
View user's profile
Send private message
i'm watching, bash away...;)
Reply to this Post
Nation Name: Caylaconia
Ruler Name: badbigwlly
Nation Resources: Gems and Rubber
http://www.cybernations.net/nation_drill_display.asp?Nation_ID=118197
http://www.cybernations.net/default.asp?Referrer=badbigwlly
EnjoiNY
Black Bull
Posts: 314
View user's profile
Send private message
Re: i'm watching, bash away...;)
Reply to this Post

Is there any way to not have automatic double spacing... or save my space bar formatting for that matter.. I tried to post some code, but with all the spaces I put in to line it up right, when I actually posted it, it was all messed up Sad

buti_oxa
MFO Wiz
Posts: 3811
View user's profile
Send private message
Well...
Reply to this Post

You can go to HTML mode by clicking on Source button, and then input your code there inside PRE tag.

Edit - that does not seem to work.

EnjoiNY
Black Bull
Posts: 314
View user's profile
Send private message
Re: Well...
Reply to this Post

#!/bin/bash
#
#A script: Ask for user real name and store in variable to retrieve later
#
noinput=""
#
echo "Please enter your name = = > \c"
read confirm_reply
#
if ["$confirm_reply" = '$noinput"]
    then
       echo "No name was entered. Please enter your name."
    else
       real_name=$confirm_reply
fi

EnjoiNY
Black Bull
Posts: 314
View user's profile
Send private message
Re: Well...
Reply to this Post

The only variable I need to initialize here would be 'noinput', correct? I'm not sure how to initialize it as literally no input. When I run this script, whatever is entered for the name get's returned as:

line 10: [NAME: command not found

EnjoiNY
Black Bull
Posts: 314
View user's profile
Send private message
Re: Well...
Reply to this Post

#!/bin/bash
#
#A script to determine if the user name already exists.
#
echo "Please enter your user ID ==> \c"
read confirm_reply
#
if ["$confirm_reply" = '$noinput"]
    then
       echo "No user ID was entered. Please enter your user ID."
    else
       user_id=$confirm_reply
       home_directory="/u/$user_id"
       if ["$user_id" = "$(cat /u/reedk/ulist|cut -f1 -d':'|grep $user_id)" ]
          then
         echo "User ID already exists."
          else
         echo "Home Directory set: $home_directory"
         echo "User ID set: $user_id
       fi
fi

EnjoiNY
Black Bull
Posts: 314
View user's profile
Send private message
Re: Well...
Reply to this Post

Again, I am at a loss for initializing variables... which ones, and how ?

EnjoiNY
Black Bull
Posts: 314
View user's profile
Send private message
Re: Well...
Reply to this Post

Alright... I think I figured out bow to init my variables. Below is the complete add user script I am trying to make work.

line 53: syntax error near unexpected token `0'  (RED)

 

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

#!/bin/bash
#
#  complete add user script
#
initialize_variables ()
{
noinput=
user_name=' '
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

EnjoiNY
Black Bull
Posts: 314
View user's profile
Send private message
It works.. nice.
Reply to this Post
Carlopan
Mr. EAD
Posts: 4
View user's profile
Send private message
Re: It works.. nice.
Reply to this Post

Hi

I don't know program language

would you please convert it to an application or a spreadsheet?

and if you do it beginners (like me) can use it

Exca06
Mr. EAD
Posts: 2
View user's profile
Send private message
Re: i'm watching, bash away...;)
Reply to this Post
EnjoiNY wrote:

Is there any way to not have automatic double spacing... or save my space bar formatting for that matter.. I tried to post some code, but with all the spaces I put in to line it up right, when I actually posted it, it was all messed up Sad

You can text me if you have any problems

   Index » MFO Software Development » Bash Scripting
 
Display posts from previous: