我有这个代码来改变文件系统的大小。问题是,即使if条件满足,它也不会进入if条件,我根本没有if条件来检查if条件。它直接进入else状态。你知道吗
post-install-ray.py chpasswd
chpasswd root:Deepsky24
df -g | grep -w / | awk '{ print $3 }' 0.89
df -g | grep -w /usr | awk '{print $3 }' 5.81
chfs -a size=+4G / Filesystem size changed to 10354688
代码:
import subprocess
import sys
import pexpect
from pexpect import pxssh
import logging
password = "Deepsky24"
hostname = "host"
username = "root"
def change_filesystem():
child = pxssh.pxssh()
child.login(hostname, username, password)
child.sendline("df -g | grep -w / | awk '{ print $3 }'")
child.prompt()
output1 = child.before
print output1
child.sendline("df -g | grep -w /usr | awk '{print $3 }'")
child.prompt()
output2 = child.before
print output2
if (output1 <= 1 and output2 >= 4):
child.sendline('chfs -a size=-3G /usr')
child.prompt()
print(child.before)
child.sendline('chfs -a size=+3G /')
child.prompt()
print(child.before)
else:
child.sendline('chfs -a size=+4G /')
child.prompt()
print(child.before)
if __name__== "__main__":
change_filesystem()
你的两个输出仍然是字符串,你需要把它们转换成浮点数
我猜你的电脑在Python2上。你知道吗
child.before
返回字符串。 将字符串与整数进行比较会得到意外的结果。 用int()
或float()
转换输出对于python3,你会有一个例外
相关问题 更多 >
编程相关推荐