The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Shell script problems to do cleansing_flame Shell Programming and Scripting 0 11-27-2007 06:19 AM
Problems with an if/then loop within a script lodey Shell Programming and Scripting 3 09-17-2007 11:45 PM
Stock script problems hinch UNIX for Dummies Questions & Answers 1 05-23-2006 11:48 PM
Problems with Perl/KSH Web Log Script mmanders Shell Programming and Scripting 3 05-03-2006 03:32 AM
script problems hellsd UNIX for Dummies Questions & Answers 3 06-13-2005 05:17 PM

Closed Thread
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 09-18-2001
Registered User
 

Join Date: Sep 2001
Location: GUess
Posts: 15
Angry having ksh script problems

well i have written a script to telnet and ftp to all my servers, the script runs great, BUT i can not for the life of me figure out how to get the script to repeat if the conditions are not filled.

this is what i have so far
Code:
#########################################
TorF(){

        echo T for Telnet or F for FTP
        read TF

        if [ $TF = "F" ] || [ $TF = "f" ]
        then
                ftp $IPADD
        fi
        if [ $TF = "T" ] || [ $TF = "t" ]
        then
                telnet $IPADD
        fi


}
##########################################

clear
#
echo "Please Select The site your would like to Telnet/FTP to."
#


echo      1. server1
echo      2. server2

echo "Please Make Your Selection. \c"
        read ANS

        case $ANS in
                '1')
                        IPADD='001.001.001.001'
                        ;;
                '2')
                        IPADD='111.111.111.111'
                        ;;
        esac
        TorF

#########################################
what i have been trying to do is have it start again if you do not meet the conditions. but i only want it to do that 2 times, before it will bring you back to a prompt......



I am stumped

any help would be great

added code tags for readability --oombera

Last edited by oombera; 02-18-2004 at 01:04 PM.
Forum Sponsor
  #2  
Old 09-18-2001
LivinFree's Avatar
Goober Extraordinaire
 

Join Date: Jul 2001
Location: Portland, OR, USA
Posts: 1,584
How about something like this:
Code:
#!/usr/bin/ksh
# simple menu - doesn't really do anything
# You may need to change this:
alias echoe="/bin/echo -e"

# functions:
func_1 () {
echoe "Yay \n\n"
}
func_2 () {
echoe "Boo \n\n"
}
menu_list () {
clear
echoe "\n\n\t\tThis is the title\n\n\n"
echoe "Make your choice: \n"
echoe "To say Yay, press 1 \n"
echoe "To say Boo, press 2 \n"
echoe "To quit, press "q" \n"
}
go_ahead () {
tput smso
echoe "Press any key to return to the menu  \c"
tput rmso
oldstty=`stty -g`
stty -icanon -echo min 1 time 0
dd bs=1 count=1 >/dev/null 2>&1
stty "$oldstty"
echoe
}
func_select () {
tput smso
echoe "\nPlease make your selection ( )\b\b\c"
read selection
tput rmso
case $selection in
     1) clear ; func_1 ; go_ahead ;; 
     2) clear ; func_2 ; go_ahead ;;
     q|Q) tput rmso ; clear ; exit 0 ;;
esac
}
#
# Here is where is gets looped - basically forever, until
# the "q" option is selected, causing an explicit exit
#

while `true`
do
menu_list
func_select
done
This is similar to a lot of menu-like scripts that I've written for the folks around here that don't know (or care to know - heathens!) Unix, but need at least a little interaction to complete their job.

In case anyone was wondering why I didn't use all of ksh's cool little redundancies { such as $(true) instead of `true` }, it's because the code above is portable. It can be run by bash, sh, ksh, and their clones, with only two changes - the echoe alias, and the sh-bang line at the top.

Hope it gives you some ideas...
  #3  
Old 09-19-2001
Registered User
 

Join Date: Sep 2001
Location: GUess
Posts: 15
well thats way over my head. but it will give me alot to think about. i can follow you to a point. i have a lot to learn about scripting but this helps alot. asicly if i get what you put is the while true which will of course go on for ever, stops because it has this line

q|Q) tput rmso ; clear ; exit 0 ;; in the case statement

and the while true is killed when you enter q to exit.

please tell me if i have this right.


jerzey
  #4  
Old 09-21-2001
LivinFree's Avatar
Goober Extraordinaire
 

Join Date: Jul 2001
Location: Portland, OR, USA
Posts: 1,584
Yeah, you've got it.
It will loop as long as it's not told to exit. The tput command, and the clear command in that statement only do a cleanup - the tput rmso returns your terminal to normal, as opposed to reverse coloring, and clear, well - it clears the screen

I think you're on the right track though - I think it might be a good idea to copy and paste this script and execute it to see how it works...

Try putting the command "set -x" at the top of the script to see what's happening, and try changing it around a little to see what changes have what effect...
  #5  
Old 09-22-2001
Registered User
 

Join Date: Sep 2001
Location: GUess
Posts: 15
thanks for all the help that worked great.

now i have to get started on the next script i have to come up with.




__________________
Remember Kiddys Unix is DOS for ADULTS
Google The UNIX and Linux Forums
Closed Thread

Thread Tools
Display Modes




All times are GMT -7. The time now is 07:32 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