-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpexpect.py
More file actions
30 lines (24 loc) · 740 Bytes
/
pexpect.py
File metadata and controls
30 lines (24 loc) · 740 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/python
import re
import pexpect
import getpass
try:
password = getpass.getpass('password: ')
child = pexpect.spawn("ssh youit@189.42.52.67 -p 7222 get system status")
child.expect(".*assword:")
child.sendline(password)
child.expect(pexpect.EOF)
systemOutput = child.before
FGTSerial = ""
FGTHostname = ""
regexHostname = r"(Hostname:)\ (\w+)"
if re.search(regexHostname, systemOutput):
strFind = re.search(regexHostname, systemOutput)
FGTHostname = strFind.group(2)
regexSerial = r"(Serial\-Number:)\ (\w+)"
if re.search(regexSerial, systemOutput):
strFind = re.search(regexSerial, systemOutput)
FGTSerial = strFind.group(2)
print FGTSerial
except pexpect.ExceptionPexpect, e:
print "error: %s" % (e)