fgimian / paramiko-expect

A Python expect-like extension for the Paramiko SSH library which also supports tailing logs.
MIT License
204 stars 78 forks source link

How to put the output we get from expect prompt in a file #83

Open panda2799 opened 2 years ago

panda2799 commented 2 years ago

Hi sir,

I have been trying to log the output that i get on cmd through interact.expect() into a file. But file is not receiving anything. I am not able to find a proper code as well. Could you please help me with that.

Pasting my code for reference: interact.send("show full-configuration") with open('backup1'+'.txt','w') as file: for line in interact.expect("",timeout=1): file.write(line)

I am trying to fetch the fortigate configuration output. Please help me. Thanks!

fruch commented 2 years ago

I think something like this would do the trick:

def write_to_file(msg):
      with open('output.log', 'a') as f:
            f.write(msg)

interact = SshClientInteraction(client, output_callback=write_to_file)
fruch commented 1 year ago

@panda2799 did this helped ?