【发布时间】:2014-01-31 17:15:19
【问题描述】:
我需要远程检查不同服务器上的某些文件是否存在。服务器位于 Linux 和 AIX 中。
我尝试了 python telnet 和 linux shell 在登录时的行为不同,所以我需要为不同的操作系统使用不同的代码来识别提示符号,以便我可以通过 telnet 发出命令:
Linux:
tn = telnetlib.Telnet(self.mHost)
tn.read_until(b"login: ")
tn.write(self.mUsername.encode('ascii') + b"\n")
tn.read_until(b"Password: ")
tn.write(self.mPassword.encode('ascii') + b"\n")
(tn.read_until(b"$")).decode('ascii')
AIX:
tn2 = telnetlib.Telnet(self.mHost)
tn2.read_until(b"login: ")
tn2.write(self.mUsername.encode('ascii') + b"\n")
tn2.read_until(b"Password: ")
tn2.write(self.mPassword.encode('ascii') + b"\n")
(tn2.read_until(b">")).decode('ascii')
连接成功后,我使用了一个简单的“ls”命令来检查文件。
ls -ltr | awk -F" " '{print $5 "|" $6 "-" $7 "-" $8 "|" $9}' | tail -n 20
但是 bash shell 和 ksh shell 在某些命令中的行为可能不同,所以我需要一次写入运行无处不在的解决方案。
可供选择:Java 6、Python 3.0
【问题讨论】:
-
你能告诉你可以使用哪个版本的java吗?
-
您忘记在帖子中提出问题/问题。
-
为什么必须使用 telnet?两台服务器都没有运行 SSH 守护进程吗?