hi guys please I want to save the output logs to text file I run this script but does not work . the error show me in last 3 row
       import sys
        import telnetlib
        import getpass
        #####################
        ###### Define Host
        host=["192.168.1.164","192.168.1.169"]
        devno=len(host)
        user='ali'
        Password='cisco'

        for i in range(devno):
            print('*'*50 + ' Connected to device : '+str(host[i]) +'*'*50)
            tn=telnetlib.Telnet(host[i])
            tn.read_until(b'Username: ')
            tn.write(user.encode('ascii')+ b'\n')
            tn.read_until(b'Password')
            tn.write(Password.encode('ascii')+b'\n')
            #tn.write(b'enable' + b'\n')
            #tn.write(b"\n")
            #tn.write(b"terminal length 0\n")
            #tn.write(b"show run\n")
            #tn.write(b' show ip route\n')
            tn.write(b'  exit\n')
            print(tn.read_all().decode('ascii'))
            f = open("/home/onelabad/Desktop/output.txt", 'w')              error start from here
            f.write(print)
            tn.close()

f = open("/home/onelabad/Desktop/output.txt", 'w') error start from here

Make it simple. Try
`f = open("output.txt", 'w')

Usually the file permissions are fine for the folder we are currently in. I can't guess the permissions needed for that other path.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.