[Tutor] 2016-02-01 Filter STRINGS in Log File and Pass as VARAIBLE within PYTHON script
knnleow GOOGLE
knnleow at gmail.com
Mon Feb 1 02:53:21 EST 2016
hello all,
trying out on how to port my unix shell script to python.
get more complicated than i expected.....: (
i am not familiar with the modules available in python.
anyone care to share how to better the clumsy approach below.
regards,
kuenn
timestamp02 = time.strftime("%Y-%m-%d-%H%M%S")
banIPaddressesFile = os.popen("cat
/var/log/fail2ban.log| egrep ssh| egrep Ban| egrep " + myDate + "| awk
\'{print $7}\'| sort -n| uniq >/tmp/banIPaddressesFile." +
timestamp02).read()
banIPaddresses = open("/tmp/banIPaddressesFile." +
timestamp02,mode="r",encoding="utf-8")
print("banIPaddresses:")
print(banIPaddresses)
for banIP in banIPaddresses:
#print("banIP:", banIP)
banIP1 = banIP.rstrip("\n")
print("BanIPaddress:", banIP1)
whoisIP = os.popen("whois -H " + banIP1 + "
|egrep -i \"name|country|mail\" |sort -n |uniq").read()
print("whoisIP:", whoisIP)
More information about the Tutor
mailing list