grep -oE not portable
I'm using Zabbix on which I can use give bash command to the agent.
This 1-liner will give me all the interfaces with their IPv4 addresses. I have a 2nd expression which returns a checksum so I can detect a difference whenever someone deletes/adds/changes an ipv4 interface. This is the output on my Ubuntu-server: Code:
~# ifconfig | grep -B1 ' inet ' | grep -oE '(^[a-z0-9:]*|addr:[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)' Code:
# ifconfig | grep -B1 ' inet ' | grep -oE '(^[a-z0-9:]*|addr:[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)' I would really like a regular expression (as elegant as possible) which will give me the output similar to the first. It needs an output that can be checksummed so I can create a trigger on it. I would also like to know which behaviour is the correct one. This is my Ubuntu Lucid Lynx Code:
# set | grep ^BASH Code:
# set | grep ^BASH |
Maybe better switch to Perl ? It's pretty stable WRT features, i.e. new features are added, by very few things get broken - each Perl release undergoes a lot of regression testing.
|
I doubt the difference is in the grep implentation, but rather in the output of ifconfig. Can you post the ifconfig from both machines?
oops, turns out it is grep: see post 8 |
Code:
# ifconfig Code:
# ifconfig |
Is it maybe something to do with the versions of grep??
|
I'm wondering whether one ifconfig outputs a \t and the other " " before inet ...
I can't imagine grep being that badly broken in either of the OSes. |
I'm wondering whether one ifconfig outputs a \t and the other " " before inet ...
I can't imagine grep being that badly broken in either of the OSes. |
There are problems with some versions of grep -o
http://www.linuxquestions.org/questi...system-758692/ http://lists.gnu.org/archive/html/bu.../msg00087.html http://lists.gnu.org/archive/html/bu.../msg00012.html Changing the * into + gets the code to work on GNU grep 2.5.1 Code:
grep -oE '(^[a-z0-9:]+|addr:[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)' |
Thanks all.
It seems I need to be careful with 'grep -o' A year ago I was getting strange results with it on busybox for which I posted a ticket. This ticket was immediately followed by a fix. Also thanks for the workaround which works. CentOS 5.5 is running 'grep (GNU grep) 2.5.1' where Lucid Lynx is running 'GNU grep 2.5.4' Can I do something to make CentOS distribute a newer version or is it just something to live with? After my initial tests, I expected it to work on all Linux versions |
All times are GMT -5. The time now is 02:52 PM. |