Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Isn't a shell found on a beach? Need help nesting if's or loops. Post 302230957 by switchkill on Monday 1st of September 2008 06:21:46 AM
Old 09-01-2008
Isn't a shell found on a beach? Need help nesting if's or loops.

As of a week ago i thought a shell was somthing found on a beach.

I'm a virgin when it comes to scripting and i'm having a really bad time here.

What i need to do is prompt for a group number
grep the /etc/groups to get the GID and name

if it exists i want to prompt the user for comfirmation to add user to the group (the other part of the script...thats working) while dispalying the group name and id.

if not i want to promt the user to make a group with name and id supplied by user input via promts.

this is what i have so far.

Sorry for being such a noob.
Code:
#!/bin/bash
 
echo
echo "User ID?"
echo
read INPUT
 
TEMPIN=$INPUT;
 
TEMPTN=`grep ":${TEMPIN}:" /etc/group |cut -d: -f3`;
 
TEMPST=`grep ":${TEMPIN}:" /etc/group |cut -d: -f1`;
 
echo "True number ${TEMPTN}"
echo "True String ${TEMPST}"
echo "Input ${TEMPIN}"
 
if [ $TEMPNT==$TEMPIN ]; then
 
 
           echo  
           echo "GID        : ${TEMPTN}"
           echo "Group name : ${TEMPST}"
           echo
           echo "Already exists, do you want to use this group"
           echo
           echo "<y> or <n>"
           read INPUT
 
                 echo        
                 if [ ! $INPUT = "n" ]; then
                 GROUP_ID=${TEMPIN};
                 fi
fi
 
if [ ! $TEMPNT==1$TEMPIN ]; then
 
 
     echo
     echo "Group ID ${TEMPIN} does not exist"
     echo "would you like to create it?"
     echo
     echo "<y> or <n>"
     echo
     read INPUT
     echo
           if [ ! $INPUT = "n" ]; then
                 echo
                 echo "Enter group name"
                 read NAME
                 echo              
                 GRP=$NAME;
                 GID=$TEMPIN;
 
                       else
                       echo "Setup cannot contine without a specified group!"
                       exit
           fi
fi

 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Loops within ftp shell session

Hi guys, i need to script the sending of multiple files through one ftp session. I have done this so far: ---------------------------------------------------------------- #!/bin/sh USER=myuser PASSWD=mypass filenum=$1 x=0 ftp -n 159.167.95.199 <<SCRIPT user $USER $PASSWD binary while ... (4 Replies)
Discussion started by: zaff
4 Replies

2. Shell Programming and Scripting

Output in my shell isn't showing properly.

Hi! Can anyone tell me what went wrong in my shell script? for dt_val in `cut -f 1 -d '|' /prod/ods/satyaki/sqlldr/grp.dat` do echo $dt_val done And, the output is - 23 39 (7 Replies)
Discussion started by: satyakide
7 Replies

3. Shell Programming and Scripting

shell script, why isn't if printing message?

Why isn't printing message? 1 #!/bin/sh 2 3 something(){ 4 echo "Inside something" 5 echo $1 $2 6 } 7 val=$(something "Hello " "world") But it prints. 1 #!/bin/sh 2 3 something(){ 4 echo "Inside something" 5 echo $1 $2 6 } 7... (4 Replies)
Discussion started by: cola
4 Replies

4. Shell Programming and Scripting

Korn Shell programming (FTP, LOOPS, GREP)

Hello All, I have another Korn shell question. I am writing a script that will ftp a file from my production database to my test database. To this, I have to construct a loop that checks a specified folder for a file. If the file exists, I want it execute the ftp protocol and then exit. ... (2 Replies)
Discussion started by: jonesdk5
2 Replies

5. Shell Programming and Scripting

Problem in loops in shell scripting

Hi, #!/bin/ksh $v="" for ((i = 1 ; i <= 5 ; i++ )) do v="THerrFile_$i.err"; grep -i "$i:Error" $v >>oraerror_output.txt done My requirement is to dynamically create variable like THerrFile_1.err,THerrFile_2.err etc. where my grep needs... (5 Replies)
Discussion started by: sudhir_83k
5 Replies

6. Homework & Coursework Questions

Shell-script loops beginner

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: "Create a shell script that changes the selected word to another word in all files from selected archive. The... (1 Reply)
Discussion started by: oibanuelos
1 Replies

7. Shell Programming and Scripting

help with multiple loops in shell script

Hi Guys- I'm trying to write a script which takes date as input (mm.yy.dd) and search in the current file. If pattern doesn't exist it will then look in a backup directory and so on. being a newb i'm unable to loop over to the backup directory. hoping for some ideas, i've highlighted the... (1 Reply)
Discussion started by: Irishboy24
1 Replies

8. Shell Programming and Scripting

korn shell for loops with expect issue

Hi I have the following Korn script having multiple for loops. #!/bin/ksh EXPECT=/usr/local/bin/expect exp_internal for d in 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 i22 23 24 25 26; do for i in 01 02 03 04 05 06 07 ; do for h in 00 01 02 03 04 05 06 07 08 09 10 11 12... (2 Replies)
Discussion started by: cic
2 Replies

9. Shell Programming and Scripting

Unset variables in shell when it running two different loops

I have a script to start/stop/restart the tomcat application. When we run the script first time i.e stop/start it set all env variables(DISTRIB_ID,NAME,TOMCAT_CFG,....etc),but when we restart the tomcat it is running in the same shell.....I need to set the variables when i restart the tomcat(in the... (1 Reply)
Discussion started by: praveen265
1 Replies
All times are GMT -4. The time now is 08:30 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy