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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A better way! 2

Status
Not open for further replies.

mrn

MIS
Apr 27, 2001
3,993
GB
Hi,

Can anyone think of a nicer way to do the following, I'm creating a lpar autobuild script, got to the point where I need to check if the lpar profile already exists, is it created in line with a config file, if it is let the scripts that follow run (Add vhost / rootvg), if not stop.

Had a play with arrays and while but didn't get anywhere useful. So went for the following, but it looks nasty.


Code:
if [ "name=${_PROFILE_NAME}" = `grep name=${_PROFILE_NAME} filename.txt` ; then
 echo "ok"
 continue
else
 echo "No Match"
 exit
fi

if [ "lpar_name=${_LPAR_NAME}" = `grep lparname=${_LPAR_NAME} filename.txt ; then
 echo "ok"
 continue
else
 echo "No Match"
 exit
fi

Repeat for 20 other Vars

Any clever ideas.....?

Mike

"Whenever I dwell for any length of time on my own shortcomings, they gradually begin to seem mild, harmless, rather engaging little things, not at all like the staring defects in other people's characters."
 
Hi

I would probably do something like this :
Code:
for one in "$_PROFILE_NAME" "$_LPAR_NAME" "$_other_20_vars"; do
  if grep -q "name=$one" filename.txt; then
   echo "ok"
   continue
  else
   echo "No Match"
   exit
  fi
done
If your [tt]grep[/tt] implementation has no -q option, see if you have something similar :
man grep said:
-q, --quiet, --silent
Quiet; do not write anything to standard output. Exit immediately with zero status if any match is found, even if an error was detected.
Also see the -s or --no-messages option. (-q is specified by POSIX.)

Feherke.
 
Cool, that'll do nicely.

Mike

"Whenever I dwell for any length of time on my own shortcomings, they gradually begin to seem mild, harmless, rather engaging little things, not at all like the staring defects in other people's characters."
 
No it won't... Don't you need to be looking for

name=value for _PROFILE_NAME
lpar_name=value for _LPAR_NAME
lpar_env=value for _LPAR_ENVIRONMENT (guessing)

and 19 or so other string=value pairs for _OTHER_VARIABLES ?

HTH,

p5wizard
 
I was tinkering with arrays ([tt]"attribute_name:_VARIABLE_NAME[/tt] items") and [tt]eval[/tt] to sort out what I *think* you need. But it's at the office. I can post what I have tomorrow though.


HTH,

p5wizard
 
Code:
# set up test case
_PROFILE_NAME=lparx-normal
_LPAR_NAME=lparx
_LPAR_ENV=aixlinux
hmcprofile=/tmp/hmcp.txt
# end set up test case

arr[0]=name:_PROFILE_NAME
arr[1]=lpar_name:_LPAR_NAME
arr[2]=lpar_env:_LPAR_ENV
# add your lpar profile attributes and script variables here

for item in ${arr[*]}
do
 name=${item%:*}
 vnam=${item#*:}

 hmcvalue=$(grep "^${name}=" ${hmcprofile})
 hmcvalue=${hmcvalue#*=}
 my_value=$(eval echo \$${vnam})

 if [ "${hmcvalue}" != "${my_value}" ]
 then
  echo "mismatch (${vnam})"
  exit 1
 fi
done
echo "match"


HTH,

p5wizard
 
Feherke,

I wouldn't worry about it... ;-)

Even I am/was partly guessing what Mike has in mind. And of course my knowledge of (and experience with) power5 and power6 virtualization does give me an unfair advantage.



HTH,

p5wizard
 
Does that mean your nick is obsolete and you need to upgrade to p6wizard? Perhaps pwizard would be more futureproof? :)

Annihilannic.
 
Annihilannic's method worked with a bit of tweaking....

Code:
for CHECK in "name=${_PROFILE_NAME}" "lpar_name=${LPAR_NAME}" 
"lpar_env=${_LPAR_ENV}" "all_resources=${_ALL_RESOURCES}" 
"min_mem=${_MINMEM}" "desired_mem=${_DESMEM}" "max_mem=${_MAXMEM}" 
"min_num_huge_pages=${_MIN_NUM_HUGE_PAGES}" 
"desired_num_huge_pages=${_DESIRED_NUM_HUGE_PAGES}" 
"max_num_huge_pages=${_MAX_NUM_HUGE_PAGES}" 
"proc_mode=${BT_CPU_TYPE_MANDATORY}" "min_proc_units=${_MINCPU}" 
"desired_proc_units=${_DESCPU}" "max_proc_units=${_MAXCPU}" 
"min_procs=${_MINVCPU}" "desired_procs=${_DESVCPU}" 
"min_procs=${_MINVCPU}" "desired_procs=${_DESVCPU}" 
"max_procs=${_MAXVCPU}" "sharing_mode=${BT_CAP_STATUS_MANDATORY}" 
"uncap_weight=${BT_WEIGHT_MANDATORY}" "boot_mode=${_BOOT_MODE}" 
"conn_monitoring=${_CONN_MONITORING}" 
"max_virtual_slots=${_MAX_VIRT_SLOTS}" ; do


                                        if grep -q $CHECK 
$AB_CONFIGPROJS/$BT_PROJECT_ID/${LPAR_NAME}_profile.txt ; then
                                                echo "ok match found for 
${CHECK}"
                                                _BUILD=NO
                                        else
                                                echo "No match found for 
${CHECK}"
                                                _BUILD=NO
                                                break
                                        fi
                                done

but array's would have been nicer.....

Mike

"Whenever I dwell for any length of time on my own shortcomings, they gradually begin to seem mild, harmless, rather engaging little things, not at all like the staring defects in other people's characters."
 
Uh Mike, make that Feherke's method.
Credit where it's due...

p5, no... p6wizard ;-)
 
Sorry, I'll learn to read one day......

Mike

"Whenever I dwell for any length of time on my own shortcomings, they gradually begin to seem mild, harmless, rather engaging little things, not at all like the staring defects in other people's characters."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top