- 論壇徽章:
- 0
|
現(xiàn)在碰到一個(gè)問題:
我在snmpd.conf中定義了:
pass .1.3.6.1.4.1.2021.255.1 /root/sh1
sh1內(nèi)容如下:
#!/bin/bash
opt=$1
oid=$2
if [ "$opt" = "-g" ]; then
echo $oid
echo string
echo 1111
elif [ "$opt" = "-n" ]; then
echo $oid
echo string
echo 2222
elif [ "$opt" = "-s" ]; then
eval $4
fi
exit 0
當(dāng)我執(zhí)行snmpset -v 2c -c rwcomm localhost .1.3.6.1.4.1.2021.255.1 s "service vsftpd restart" 的時(shí)候,是可以啟動(dòng)vsftpd的。
但用程序來實(shí)現(xiàn)這個(gè)語句的時(shí)候,老是報(bào)錯(cuò)。
我的代碼如下:(用python寫的)
import netsnmp
var = netsnmp.Varbind('.1.3.6.1.4.1', '2021.255.1', 'service vsftpd restart', 'STRING')
res = netsnmp.snmpset(var, Version = 1, DestHost='localhost', Community='rwcomm')
print res
各位兄弟有沒有做個(gè)這方面的,可否帖上一段代碼?
編程語言不限!
tks! |
|