I need to check the existence of some files on different servers remotely. The servers are in Linux and AIX.
I tried python telnet and the linux shell behave differently at login so I need to use different code for different OS to recognize the prompt symbol so that I could issue command via 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')
After connection succesful, I used a simple 'ls' command to check with the files.
ls -ltr | awk -F" " '{print $5 "|" $6 "-" $7 "-" $8 "|" $9}' | tail -n 20
However bash shell and ksh shell may behave differently in some commands so I need to a once-write-run-everywhere solution.
Available choice: Java 6, Python 3.0