0

I´m a network engineer with no experience in programming, recently in python, but making small improvements everyday.

I need some help in getting multiple matches in IF statements like:

if  "access-class 30" in output and "exec-timeout 5 5" in output:
    print ('###### ACL VTY OK!!! ######')

Is it possible to check multiple keywords in a single string ? Thanks for all your time.

Seb D.
  • 5,046
  • 1
  • 28
  • 36
Tiago R.
  • 3
  • 1
  • 4
  • 1
    Possible duplicate of [Check if multiple strings exist in another string](http://stackoverflow.com/questions/3389574/check-if-multiple-strings-exist-in-another-string) – Seb D. Nov 04 '16 at 11:17

2 Answers2

1

Use the all function with a generator expression:

data = ["access-class 30", "exec-timeout 5 5"]
if all(s in output for s in data):
    print('###### ACL VTY OK!!! ######')
TigerhawkT3
  • 48,464
  • 6
  • 60
  • 97
0

Yes it is possible.

You can use regular expressions(Regex).

import re
li = [] # List of all the keywords
for l in li
  for m in re.finditer(l,output)
     if m !=None:
       print 'match found'
Rohan Amrute
  • 764
  • 1
  • 9
  • 23