Closed deneb78it closed 2 years ago
The scope of my code is to reach a remote server and remove logs from a directory. Before removing logs, I list the files with ls -l.
The same command works fine if the directory exists. It goes in stuck if the folder does not exits.
relevant code:
def remove_logs(self): try: self.channel.shell() self.channel.write('ls -l /var/log/bbb/ \n') size, data = self.channel.read() output = output + 'logdir 2 before delete\n' + data.decode() + '\n' self.channel.write('rm /var/log/bbb/FW* \n') time.sleep(1) self.channel.write('ls -l /var/log/bbb/ \n') size, data = self.channel.read() output = output + 'logdir 2 after delete\n' + data.decode() + '\n' except: return "command error" return "command sent" + '\n' + output
For this server the folder /var/log/bbb/ does not exist. When I execute the code, it goes in stuck as it reaches the read instruction below.
self.channel.write('ls -l /var/log/bbb/ \n') size, data = self.channel.read()
If I execute the command manually, this is the output:
ls -l /var/log/bbb/ ls: cannot access '/var/log/bbb/': No such file or directory
How can I fix? Thanks
Thanks for the interest.
Use parallel-ssh for high level clients based on this library.
The issue tracker is for issues with the code, not instructions on how to use.
The scope of my code is to reach a remote server and remove logs from a directory. Before removing logs, I list the files with ls -l.
The same command works fine if the directory exists. It goes in stuck if the folder does not exits.
relevant code:
For this server the folder /var/log/bbb/ does not exist. When I execute the code, it goes in stuck as it reaches the read instruction below.
If I execute the command manually, this is the output:
How can I fix? Thanks