Regular expression output as [] in Linux

This is the place for queries that don't fit in any of the other categories.

Regular expression output as [] in Linux

Postby nmskarthik » Tue Apr 23, 2013 9:33 am

Hi,

Script:
import os
import re
def pingtest(ipaddr,echoreq):
cmd = "fping " + ipaddr + " -c " + echoreq + "\n"
r = "".join(os.popen(cmd).readlines())
print r
m = re.findall("/\d+%", r)
print m
if m == ['/0%']:
print "The Target host reachable for 30 milliseconds"
else:
print "The target host not responding for the echo request"

pingtest("192.168.0.198","3")

output:
92.168.0.198 : xmt/rcv/%loss = 3/3/0%, min/avg/max = 0.94/1.00/1.11
192.168.0.198 : [0], 84 bytes, 1.11 ms (1.11 avg, 0% loss)
192.168.0.198 : [1], 84 bytes, 0.95 ms (1.03 avg, 0% loss)
192.168.0.198 : [2], 84 bytes, 0.94 ms (1.00 avg, 0% loss)

[]
The target host not responding for the echo request

In the above script execution output I am getting "print m" value as []. if I run the same script in windows based intrepreter I am geeting the /0%. Could you please let me know what i missed out in the script.

With Reagrds,
karthik.N
nmskarthik
 
Posts: 2
Joined: Tue Apr 23, 2013 4:55 am

Re: Regular expression output as [] in Linux

Postby metulburr » Tue Apr 23, 2013 11:30 am

Please use code tags
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1562
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY


Return to General Coding Help

Who is online

Users browsing this forum: Demontager, Google [Bot] and 3 guests