1828196 Members
2164 Online
109975 Solutions
New Discussion

Re: matching a regexp

 
SOLVED
Go to solution
totoperdu
Frequent Advisor

matching a regexp

Hello,

i want to auto install depots from many hosts, when i launch (for example):
swlist -v -s depot_path/file.depot |grep "^os_release "

the result is:
os_release ?.11.*

someone know how i could match $(uname -r) with "?.11.*" in a script ?

thanks

Cedrick Gaillard.
14 REPLIES 14
IT_2007
Honored Contributor

Re: matching a regexp

you can pass string like B.11.11 directly in the script to check os_release
James R. Ferguson
Acclaimed Contributor

Re: matching a regexp

Hi Cedrick:

# uname -r | sed -n '/11\..*/p'

...returns non-enpty output if matched. Does that help?

Regards!

...JRF...
Srini Jay
Valued Contributor

Re: matching a regexp

tro match the exact format, you can try:

count=`uname -r|grep -Ec ".[.]11[.].*"`

or if you just care for ".11." try this:

count=`uname -r|grep -c ".11."`

Then use $count in your if conditions... (shud be '1' if the OS is ?.11.*)
spex
Honored Contributor

Re: matching a regexp

Cedrick,

How about something like...

#!/usr/bin/sh
cd /depot_path
for f in $(ls -1 $PWD/*$(uname -r | cut -d. -f2-3)*)
do
swinstall -s ${f} \*
done
exit

PCS
Sandman!
Honored Contributor

Re: matching a regexp

# REV=$(uname -r)

# echo $REV | awk '$0~/^.\.11\..*$/'
OR
# echo $REV | grep ".\.11\.*"
totoperdu
Frequent Advisor

Re: matching a regexp

sorry i'm not at work for now (i can't test) but nothing seems to be what i want to do.

the result of 'swlist -v -s depot_path/file.depot |grep "^os_release "' could be:
?.11.* or ?.1[10].* or anithing else.

the result of 'uname -r' could be:
A.11.00 or B.11.23 or anything else.

i have tried to do something of simple:
echo 'B.11.11' |grep -E '?.11.*'

but that seems to work only on GNU grep ;(
hpux grep don't know the '?' char and i can't install GNU grep on all servers i want to auto-install the depots.

when i have started to write this auto-install script, i have renamed the original depots under the form:
$(uname -r).${PA_or_IA}$(getconf KERNEL_BITS).${softname}.depot

with that, i have create symlink for all versions supported by the depot but it's very dirty.
i did it temporary, until i finish to read the SD-UX documentation and the only way i found for something of clean is to extract the informations from the depot, so, i must deduct the name of the good package by interrogating all depots that matches the $softname var.

thanks.

Regards,
Cedrick Gaillard.
Sandman!
Honored Contributor

Re: matching a regexp

>echo 'B.11.11' |grep -E '?.11.*'

try this...

# echo 'B.11.11' | grep "^[A-Z]\.11\.[0-9][0-9]$"
OR
# echo 'B.11.11' | grep "^[A-Z]\.11\.[0-9]\{2\}$"

hope it helps!
Dennis Handly
Acclaimed Contributor
Solution

Re: matching a regexp

(Note you can use "-a os_release" instead of -v and grep.)

I assume you want to use the value of os_release to see if it matches your OS version. If so, given OS_PATTERN="?.11.*", you can use shell pattern matching inside of [[ ]]:
if [[ "$(uname -r)" = $OS_PATTERN ]]; then echo TRUE; else echo FALSE; fi

If you want to use grep/awk regular expressions, you can change the "." to "\." and then "?" to ".":
XX=$(echo "?.11.2*" | sed -e 's/\./\\./g' -e 's/?/./g')
totoperdu
Frequent Advisor

Re: matching a regexp

big thanks Denis,

$OS_PATTERN works very fine ;)

my problem is solved, big thanks all for your help.



PS:
"-a os_release" does not seems to work as expected beacause the result needs to be piped by grep in all manner:
$ swlist -v -s /depot/PHCO_27779.depot -a os_release
# Initializing...
# Contacting target "nr0u0169"...
#
# swlist Depot Table of Contents
#
# For depot: nr0u0169:/depot/PHCO_27779.depot
#
# Date: Fri Sep 8 10:12:40 2006
#

#
# No Bundle(s) on nr0u0169:/depot/PHCO_27779.depot
# Product(s):
#

PHCO_27779
vendor
product
os_release B.11.00

Dennis Handly
Acclaimed Contributor

Re: matching a regexp

>"-a os_release" does not seems to work as expected because the result needs to be piped by grep in all manner:
$ swlist -v -s /depot/PHCO_27779.depot -a os_release

When you use -a, you should remove the -v:
$ /usr/sbin/swlist -a os_release
# Bundle(s):
B3693AA ?.11.2*
B3901BA B.11.2[23]|B.11.31
totoperdu
Frequent Advisor

Re: matching a regexp

it's identical, the result needs to be piped:
$ swlist -s /depot/PHCO_27779.depot -a os_release
# Initializing...
# Contacting target "nr0u0169"...
#
# Target: nr0u0169:/depot/PHCO_27779.depot
#

#
# No Bundle(s) on nr0u0169:/depot/PHCO_27779.depot
# Product(s):
#

PHCO_27779 B.11.00
Arturo Galbiati
Esteemed Contributor

Re: matching a regexp

Hi Cedrick,
this run on Hp-UX:
echo 'B.11.11' |grep -E '(.)*\.11\.(.)*'

(.)*=? in your example
\. to be sure to look for . (. it's a wildcard)
(.)*=* in your example

in general (.)* means any number of chars


HTH,
Art
Arturo Galbiati
Esteemed Contributor

Re: matching a regexp

Hi Cedrick,
if you need more info:
man 5 regexp
Hth,
Art
totoperdu
Frequent Advisor

Re: matching a regexp

hello Art,

my problem is solved.

thanks for your input.