1

hi I am coding the python script to login telnet and it has to write log file to op.txt

the absolute path is

/netperf/mntpt/array1/home/prg_use/op.txt

the python code

ptlog.py

import getpass
import sys
import telnetlib
import time

host ="12.12.1.123"
user ="user_name"
passwd ="telnet_password"
tn = telnetlib.Telnet(host)
tn.read_until("login: ")
tn.write(user + "\n")
tn.read_until("Password: ")
tn.write(passwd + "\n")
tn.write("touch op.txt \n")
time.sleep(5)
tn.write("lr \n")
str_all=tn.read_until("$")
#f=open("/netperf/mntpt/array1/home/prg_use/op.txt", "w")
f=open("op.txt", "w")
f.write(str_all)
f.close()
tn.write("exit \n")

print tn.read_all()

the server side in terminal is

$

 lr: not found
$

however, I wanna it wrote

lr: not found

in

op.txt

but it did not happen, can any one tell me how to do it, thank you

if I code

f=open("/netperf/mntpt/array1/home/prg_use/op.txt", "w")

it will show

no such file or directory '/netperf/mntpt/array1/home/prg_use/op.txt'

I think it is not the path problem, I can touch op.txt

, its

str_all=tn.read_until("$")

can not copy the return message and then write in op.txt

lin Joe
  • 82
  • 1
  • 9
  • It seems you have two very different questions here, making this post to broad really. Please take some time to read [the help pages](http://stackoverflow.com/help), especially the sections named ["What topics can I ask about here?"](http://stackoverflow.com/help/on-topic) and ["What types of questions should I avoid asking?"](http://stackoverflow.com/help/dont-ask). Also please [take the SO tour](http://stackoverflow.com/tour) and [read about how to ask good questions](http://stackoverflow.com/help/how-to-ask). One question per question please. – Some programmer dude Jan 12 '18 at 07:09
  • thank you , I change the topic to "put the message in a particular log file" – lin Joe Jan 12 '18 at 07:15
  • @joe Are you sure you are able to access '/netperf/mntpt/array1/home/prg_use/' folder structure from the python script folder? – Rakesh Jan 12 '18 at 07:34
  • if I use python shell in server side and relative path"f=open("op.txt", "w")" then I can wrote something in op.txt,,and the python telnet is ok ,I can python telnet in and do such as,,ls , mkdir ,,,etc. – lin Joe Jan 12 '18 at 07:40
  • I think it is not the path problem its "str_all=tn.read_until("$")" can not copy the return message and then write in op.txt – lin Joe Jan 12 '18 at 08:36

0 Answers0