Re: case help (159 Views)
Reply
Trusted Contributor
lawrenzo
Posts: 383
Registered: ‎06-06-2003
Message 1 of 5 (159 Views)
Accepted Solution

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
Please use plain text.
Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 2 of 5 (159 Views)

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...
Please use plain text.
Honored Contributor
Sandman!
Posts: 2,220
Registered: ‎01-13-2005
Message 3 of 5 (159 Views)

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
Please use plain text.
Acclaimed Contributor
Dennis Handly
Posts: 24,977
Registered: ‎03-06-2006
Message 4 of 5 (159 Views)

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
Please use plain text.
Trusted Contributor
lawrenzo
Posts: 383
Registered: ‎06-06-2003
Message 5 of 5 (159 Views)

Re: case help

ok thanks for the input.

I'll let you know how I get on ...
hello
Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation