我尝试使用 paramiko
在 Python 中编写一个简单的代码,以使用 ncdu
命令检索远程目录的磁盘空间使用情况。但是 ncdu
似乎没有与 paramiko
一起工作。 ncdu
使用 ncurses
。谁能帮我提供解决方法?
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('xxxx', username='root', password='xxxx')
dom="xxxx"
stdin, stdout, stderr = ssh.exec_command('/scripts/whoowns %s' %dom)
test=(stdout.readlines())
new=test[0].strip()
stdin, stdout, stderr = ssh.exec_command('ncdu -q /home/%s/public_html/' %new)
print (stdout);
ssh.close()
最佳答案
使用“更原始”的命令:
du -hs /directory/
检索目录的维度。
-s 代替默认输出,仅报告每个指定文件的总和。
-h 以人类可读格式打印尺寸(例如,1K 234M 2G)
手册页链接 here .
关于python - 用于在 linux 中读取 ncdu 命令结果的 paramiko Python 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28426291/