HI ,
I have a awk statement like this ..
ps -ef |grep pmon|grep +ASM|awk '{print \$NF}'| cut -d"_" -f3
what it will do is
oracle 42480 1 0 Feb 08 - 24:08 ora_pmon_xxxx
it will return xxxx ( dbname) .
I want to modify the above statement ( it;s failing on solaris platform ) . Any ideas to modify this script to get rid of awk part ?
Thanks
ps -ef |grep pmon|grep +ASM|awk '{n=split(/_/,arr,$NF);print arr[n]}'
Thankyou . But it didn't help ..
ps -ef |grep pmon|grep w414d|awk '{n=split(/_/,arr,$NF);print arr[n]}'
1
my problem is my statement is working most of the time but some times it's not returning the correct value . May be because awk filed problem (?) ..
I always want to parse that last line in the output .e.g.
oracle 42480 1 0 Feb 08 - 24:08 ora_pmon_xxxx
what ever values in between I don't care . I am using awk and cut ststement to do this . But it's failing .any ideas to improve this code ?
Thanks
Hi,
What failed? Put here the input line of awk, I mean after ps -ef |grep pmon|grep w414d
and the awk's output.
You may take last line by 'tail -1' :
ps -ef |grep pmon|grep w414d | tail -1
This is the command I am using :
ps -ef |grep pmon|grep xxxx |awk '{print \$NF}'| cut -d"_" -f3
to parse this kind of output :
oracle 31060078 1 0 May 08 - 37:05 ora_pmon_xxxx
and it's working most of the time and some times it's failing with this message :
Connection to Server -f3 failed
so instaed of giving DB name it's giving the -f3 .
didn't understand why it's giving -f3 sometimes ?
Thanks
not tested
ps -ef |nawk '/pmon/ && /xxxx/ {match($NF, "_[^_]*$"); print substr($NF,RSTART+1)}'
If you "hate" awk, you can use sed ^^
echo "oracle 42480 1 0 Feb 08 - 24:08 ora_pmon_xxxx" | sed 's/.*_//g'
when I execute this ...
ps -ef |nawk '/pmon/ && /xxxx/ {match($NF, "_[^_]*$");print substr($NF,RSTART+1)}'
it's returning the below output ....
xxxx
substr($NF,RSTART+1)}
it should return xxxx not with substr.
Thanks
$ echo 'oracle 31060078 1 0 May 08 - 37:05 ora_pmon_xxxx' | nawk '/pmon/ && /xxxx/ {match($NF, "_[^_]*$");print substr($NF,RSTART+1)}'
xxxx
Validate your code.