Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

if $SS1 = "003" then??

Status
Not open for further replies.

blodwyn

IS-IT--Management
Mar 23, 2001
24
0
0
I'm sure this is an easy one for you gurus out there but not for my limited experience.

One particular joblog gives 5 possible completion status codes:- 003, 004, 005, 006, 007 for each phase of the job.
If the result is 003, 004 or 005 I need to exit without going onto the next phase. Any other code means that the job can continue with the next selection.

I can easily retrieve this status code after each phase but I'm having difficulty with the syntax for the "if...then" expression.

Any suggestions most gratefully received.

Regards

Blodwyn
 
if [ $code -ge 003 -a $code -le 007 ]; then
exit;
fi;



vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Thanks for that vlad.
Below is my fresh attempt, what have I done wrong?

saturn:blodwyn 12% vi temp2

#!/bin/sh

SS1=`cat /home/tasks/logfile|grep STOP|tail -1|awk '{print $5}'`
echo $SS1
if [$SS1 -ge 003 -a $SS1 -le 007]; then
exit
fi;
~
~
~~~
~
&quot;temp2&quot; 8 lines, 152 characters

saturn:blodwyn 13% ./temp2

004

./temp2: [004: not found
saturn:blodwyn 14%

Cheers
Blodwyn
 
common mistake - '[' and ']' are to have spaces surrounding them like so:

if [ $SS1 -ge 003 -a $SS1 -le 007 ]; then

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Hi vlad

That did the trick, thanks for your help.
(You wouldn't believe how long I've been looking at this!)

Regards

Blodwyn

 
I now have a script that will execute a command on a list of objects (for X in 'cat list' do ........).

Courtesy of vgersh99, should a particular error code(s) result, the job will exit without proceeding to the next object on the list.

My next requirement is to process multiple lists in the same way BUT, on erroring when processing an object in a list, to abort that list and proceed to the next list without exiting.

Any ideas?

Regards

Blodwyn

 
for LISTS in `ls YOUR_LIST_FILES` or LIST1 LIST2 LIST3...
do
for DATA in `cat ${LISTS}`
do
YOUR_CODE_HERE
# Don't use exit, use return instead
done
done

# Man ksh or sh, etc. Return will allow you to stop processing the current item and go back up to the next item in the loop.
 
Thanks
Obviously I'm missing something here, hoping that the script would now proceed to the next file in the filelist after an error 0008.

Can you help me further?

Regards

Blodwyn

saturn:blodwyn 46% vi script

#!/bin/sh

for LIST in `ls filelist`
do

for DATA in `cat ${LIST}`
do

for R in `cat $DATA`
do

echo $R

code=`cat logfile|grep $R|grep MON|grep -w 'P'|tail -1|awk '{p
rint $4}'`

echo $code
if [ $code -ge 0008 ] ; then

return

fi;

done
done
done

saturn:blodwyn 47% ./script

TEST152003
0000

TEST162003
0008

./script: cannot return when not in function
 
instead of doing a 'return', do 'continue'.

FYI, I'd name your script some other than 'script' [man script].

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Hi again vlad

When I use continue instead of return, the job continues to the next object in the present list after an error code ge8?

Blodwyn
 
correct

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Sorry for being a dumb blonde, but I really wanted to be able to abort the current list in the event of an error (for example ge8) and go onto the next list of objects in the filelist, and so on.
Is that possible?

Regards

Blodwyn
 
you can do either:
continue 2;
OR
break;

I don't quite follow the logic of your script, but you can try either one of the above.

from 'man ksh'

* break [ n ]
Exit from the enclosed for , while , until , or
select loop, if any. If n is specified then
break n levels.

* continue [ n ]
Resume the next iteration of the enclosed for ,
while , until , or select loop. If n is specified
then resume at the n-th enclosed loop.


vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Thanks for all your help. &quot;break 1&quot; seems to do what I want.

(The script is only a simplified test version with &quot;echo&quot; replacing other command(s).)

Regards

Blodwyn
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top