我正在尝试使用 python 通过 SSH 执行所有多个命令。
每次,我都会收到一个“意外的(”)错误。
请为此提供正确的语法。谢谢你。
os.popen('''ssh -o BatchMode=yes -o StrictHostKeyChecking=no '''+host+''' 'echo "<td>" $(uname -ri) "</td>"; free | grep "Mem:" | awk '\''{ print "<td>" $2/1024 " MB (" int($4*100/$2) "%) </td>" }'\''; free | grep "Swap:" | awk '\''{ print "<td>" int($3*100/$2) "%" }'\''; echo "</td><td>" $(cat /proc/cpuinfo | grep "processor" | wc -l) "@" $(cat /proc/cpuinfo | grep "MHz" | sort -u | awk '\''{ print $4 }'\'') "Mhz" $(cat /proc/cpuinfo | grep "cache size" | sort -u | awk '\''{ print "(" $4 " " $5 ")</td>" }'\'')'" ''').read()
截至目前,我正在使用:
data1=os.popen('''ssh -o BatchMode=yes -o StrictHostKeyChecking=no '''+host+''' 'echo "<td>" $(uname -ri) "</td>";' ''').read().rstrip()
data2=os.popen('''ssh -o BatchMode=yes -o StrictHostKeyChecking=no '''+host+''' free | grep "Mem:" | awk '{print "<td>" $2/1024 " MB("int($4*100/$2)"%)</td>"}' ''').read().rstrip()
data3=os.popen('''ssh -o BatchMode=yes -o StrictHostKeyChecking=no '''+host+''' free | grep "Swap:" | awk '{ print "<td>" int($3*100/$2) "%" }' ''').read().rstrip()
data4=os.popen('''ssh -o BatchMode=yes -o StrictHostKeyChecking=no '''+host+''' cat /proc/cpuinfo | grep "processor" | wc -l ''').read().rstrip()
data5=os.popen('''ssh -o BatchMode=yes -o StrictHostKeyChecking=no '''+host+''' cat /proc/cpuinfo | grep "MHz" | sort -u | awk '{ print $4 }' ''').read().rstrip()
data6=os.popen('''ssh -o BatchMode=yes -o StrictHostKeyChecking=no '''+host+''' cat /proc/cpuinfo | grep "cache size" | sort -u | awk '{ print "(" $4 " " $5 ")</td>" }' ''').read().rstrip()