having ksh script problems


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers having ksh script problems
# 1  
Old 09-18-2001
Network 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 04:04 PM..
# 2  
Old 09-19-2001
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-20-2001
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
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 Smilie

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
thanks for all the help that worked great.

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




Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

problems with ksh array and find command

set -A allfiles `find $usrhtml -type f` i am trying to populate this array with the find command. It works fine when find is looking through a single directory but when i add a new subdirectory the files in the subdirectory get duplicated. Can anyone help me and fix this so each files in... (1 Reply)
Discussion started by: bjhum33
1 Replies

2. Shell Programming and Scripting

Problems with ksh

I have the following ksh code and I am passing f="npt06-sr40-syn-dc0p02-32x24drw.mis" For some reason, it's going to the else statement instead of setting optfdrw=1 smptag=$(print -R $f | awk '/smp/') drwtag=$(print -R $f | awk '/drw/') if && ; then # drw tag... (15 Replies)
Discussion started by: kristinu
15 Replies

3. Solaris

Problems Running KSH on Solaris 10

Hi, I am currently in the process of testing upgrading from Solaris 8 to Solaris 10. one problem i have encountered is when i am running any of my batch scripts. All my scripts start with #! /bin/ksh so that they will excuted in the ksh shell. but the scripts will not run correctly. The... (3 Replies)
Discussion started by: dshakey
3 Replies

4. Shell Programming and Scripting

KSH script to run other ksh scripts and output it to a file and/or email

Hi I am new to this Scripting process and would like to know How can i write a ksh script that will call other ksh scripts and write the output to a file and/or email. For example ------- Script ABC ------- a.ksh b.ksh c.ksh I need to call all three scripts execute them and... (2 Replies)
Discussion started by: pacifican
2 Replies

5. Shell Programming and Scripting

autosys/ksh - problems with script

Hi, I'm using autosys and want to set it up that I receive emails when certain jobs start and finish. I don't want to edit each jobs script (ksh) to send a mail at start and finish, I would rather have a single script/job that watches for a trigger when the jobs have started or finished. I... (1 Reply)
Discussion started by: weszardoz
1 Replies

6. Shell Programming and Scripting

import var and function from ksh script to another ksh script

Ih all, i have multiples ksh scripts for crontab's unix jobs they all have same variables declarations and some similar functions i would have a only single script file to declare my variables, like: var1= "aaa" var2= "bbb" var3= "ccc" ... function ab { ...} function bc { ... }... (2 Replies)
Discussion started by: wolfhurt
2 Replies

7. Shell Programming and Scripting

Strange parameter passing problems (KSH)

Hi all, I'm having a rather peculiar problem involving parameter passing with declared functions in my shell script. Hope to get some advice here. A brief description of my code is as follows: However, I'm not getting the results I wanted. If I pass in $rdir, I'm going to end up... (4 Replies)
Discussion started by: rockysfr
4 Replies

8. Shell Programming and Scripting

tracing a ksh script within a ksh script

I normally trace a script with the ksh -x <script name> and redirect strderr to file. But if you have a script like the examble below...... vi hairy bear=`grep bear animals` if then ksh more_animals fi If I ksh -x hairy it won't trace "more_animals" unless I put a -x in it. Is... (1 Reply)
Discussion started by: shorty
1 Replies

9. Shell Programming and Scripting

executing a ksh script from another ksh script

Hi, I'm new to unix scripting.How can i call a script from another script. I have a.ksh and b.ksh .I have to call b.ksh from a.ksh after it is successfully exceuted. I tried using #!/bin/ksh -x in a.ksh and at the end i have used /path/b.ksh My problem is it is executing only a.ksh.it... (6 Replies)
Discussion started by: ammu
6 Replies

10. Shell Programming and Scripting

Problems with Perl/KSH Web Log Script

Hi, I am writing a series of scripts for work to analyse intranet access logs. All of the scripts do as they should when run individually from the shell, but only when run from certain directories. This sounds like it may be a PATH issue but I am not sure. When I run a certain script, say... (3 Replies)
Discussion started by: mmanders
3 Replies
Login or Register to Ask a Question