Results 1 to 6 of 6
First, this forum rocks! Lot's of real good advise out there.
Next, at the risk of admitting I'm a novice ...
I'm trying to write a script in ksh that ...
- 01-05-2009 #1Just Joined!
- Join Date
- Dec 2008
- Location
- e-burgh, PA
- Posts
- 4
[SOLVED] Controlling a do while loop
First, this forum rocks! Lot's of real good advise out there.
Next, at the risk of admitting I'm a novice ...
I'm trying to write a script in ksh that controls itself - you know, like a program should... A procedure, to do a set of commands, evaluate them, change a Control_Value to progress the script, allow it to move on, or wrapup and return control to a master control program.
I think I need a good example of a procedure, that changes the value of an expression during an if then else statement; so that if a good run is detected, it moves on to the next piece of the pie...
And this is just an illistration - and not - meant to be actual script... That is what I'm hoping younze all can help me with.
Thanks in advance and Happy New Year!
GetFirst="Control_1"
do while $Control_1
~/bin/SomeExpectScript 1>~/LOGFILE1 2>&1
if [ grep $TextValue ~/LOGFILE = $CompareValue ]
then
echo " MATCH "
... ... ... Do more commands, notify, log, etc
GetNext="Control_2"
else
~/bin/WrapUp_Errors_Detected_Script
exit 1
fi
done
do while $Control_2
~/bin/SomeExpectScript 1>~/LOGFILE2 2>&1
if [ grep $TextValue ~/LOGFILE2 = $CompareValue ]
then
echo " MATCH "
GetNext="Control_3"
... ... ...
else
~/bin/WrapUp_Errors_Detected_Script
exit 1
fi
done
do while $Control_3
~/bin/SomeExpectScript 1>~/LOGFILE3 2>&1
if [ grep $TextValue ~/LOGFILE3 = $CompareValue ]
then
echo " MATCH "
GetNext="Success_Wrapup"
else
~/bin/WrapUp_Errors_Detected_Script
exit 1
fi
Proc $Success
~/bin/SomeExpectScript 1>~/SomeExpectScript.log 2>&1
... ...
- 01-06-2009 #2Linux User
- Join Date
- Mar 2008
- Posts
- 287
Controlling a do while loop
U hav a goood start already I can see that you may be familiar with VB or C++.
B careful of capitalizing within a variable name bcuz after awhile one tends to forget such trivia and u get an oops. One other thing too is to indent ur code!!! 4 readability.
I like the way u use if (i prefer bash to ksh but that is personal pref and usually my scripts end up as bourne shell scripts) i.e.
if [ xxxx ]
xxxxxxxxxxxx
then
yyyyyyyyyyy
else
zzzzzzzzzzz
fi
U might ought to check on differences between exec-ing a script and spawning one, see book "Unix Power Tools" and especially section on "Handling Files Line-by-Line". How spawning occurs can keep U outa trouble when calling a script from a script. Also u may want to use "system" calls so read on that too.
Otherwise I think you hav it so slog away. Oh comment out calls to other scripts initially and use an echo -e "TEST xxxxxx" so u know how it is going b4 u run when actually calling other scripts.
PS
why use do while if while works? maybe u r converting something?
- 01-06-2009 #3Just Joined!
- Join Date
- Dec 2008
- Location
- e-burgh, PA
- Posts
- 4
Thanks clickit.... i stink at scripting... Agree, a while makes more sense - been reading the Advance Scripting Guide from tldp.org. I am converting some old stuff - i found which really needs flushed. I am trying to establish a method to enter "CONTROL BREAKS" ... if successful finding do next step, etc... I wish I knew C .. I've never been to a unix scripting class... self taught ... catcha ltr...
- 01-06-2009 #4Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Hi.
I find that formatting is pain, so I gather formatting tools. One I have found for shell scripts is at: * Bash Script Beautifier
Curiously, it is written in ruby, but I think that that makes it more flexible (assuming you have ruby installed)
Note also that using CODE tags when posting code and data here will make it far more readable, and so may attract more replies ... cheers, drlWelcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )
- 01-06-2009 #5Just Joined!
- Join Date
- Dec 2008
- Location
- e-burgh, PA
- Posts
- 4
Hey drl - thanks for the tip. Don't have ruby installed. I'll ask about it. The box I'm on in a redhat release. Didn't find it with the which command. Would come in real handy I bet for making the scripts readable. Most of them are. Sorry I got lazy posting my sample question above.
If you or anyone can point out a previous post on handling one to many files in a retrevial process - that would be super. I will search for some - but, maybe someone has a fav to share.
Tschüß
- 01-09-2009 #6Linux User
- Join Date
- Mar 2008
- Posts
- 287
I found this pdf:
advancedBashScriptingGuide.pdf
by Mendel Cooper. I have only had time to scan it but it is LOADED with scriipts. A good way to learn


