Executing a command over SSH with python -


i trying execute multiple commands on ssh python.

every time, "unexpected (" error.

please give correct syntax this. thank you.

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() 

as of now, using:

 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() 

i think it's best if use proper library doing that. i've worked paramiko , pretty straightforward.

take pick: http://wiki.python.org/moin/secureshell


Comments