1748136 Members
3920 Online
108758 Solutions
New Discussion юеВ

Re: case help

 
SOLVED
Go to solution
lawrenzo
Trusted Contributor

case help

I am creating a module within a script and would like some assistance:

on AIX i run the following command

root@tstestcl.eu.unilever.com # sysdumpdev -l
primary /dev/lg_dumplv
secondary /dev/lg_dumplv2
copy directory /var/adm/ras
forced copy flag TRUE
always allow dump TRUE
dump compression ON

this is the correct output on this system however it is not the case on all systems and I have over 1000 systems to check ....

I was going to use $1 to provide the string for the case statement

case $1 in

primary )

if [[ $2 = /dev/lg_dumplv ]] ; then

continue
else
echo "Run Funtions"
fi
;;

secondary )

if [[ $2 = /dev/lg_dumplv2 ]] ; then

continue
else
echo "Run Funtions"
fi
;;

copy )

if [[ $2 = /var/adm/ras ]] ; then

continue
else
echo "Run Funtions"
fi
;;

forced )

if [[ $2 = TRUE ]] ; then

continue
else
echo "Run Funtions"
fi
;;

always )

if [[ $2 = TRUE ]] ; then

continue
else
echo "Run Funtions"
fi
;;

dump )

if [[ $2 = ON ]] ; then

continue
else
echo "Run Funtions"
fi

from the command out put I can assign $1 to be the first filed and $2 to be the last field however I am having difficutly running this into awk ..

what would the most effeicient way to have $1 and $NF to be read by the case statement or is there a better solution for this?

thanks again for any help !

Chris.
hello
4 REPLIES 4
James R. Ferguson
Acclaimed Contributor
Solution

Re: case help

Hi Chris:

If I understand your objective, you want to parse the command output and pass this to your script using the first and the last fields of each parsed line as the script's $1 and $2 :

# ./myecommand | awk '{print $1,$NF}' | while read A B;do ./myscript ${A} ${B};done

Regards!

...JRF...
Sandman!
Honored Contributor

Re: case help

How about trying the awk construct below. it can be extended to include all the line parsing you need done i.e.

# awk '{if($1=="primary") if($NF!="/dev/lg_dumplv") print "Run Functions"}' file
Dennis Handly
Acclaimed Contributor

Re: case help

If these are the only 6 valid lines and the spacing is exactly the same and the echo is the same, you can simply grep -vf:
$ grep -vf valid-output input-file

Of course if you get some output, you'll have to decode it to print an error. Or you can just print the whole output and say these are the bad lines:
grep -vf valid-output input-file > bad_file
if [ -s bad_file ]; then
echo "Run Functions"
# print or remove bad_file
fi
lawrenzo
Trusted Contributor

Re: case help

ok thanks for the input.

I'll let you know how I get on ...
hello