spawn snmptrap from python

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kaf3773
    New Member
    • Jan 2012
    • 20

    spawn snmptrap from python

    Hi
    I am trying to spawn an snmptrap from python but i keep getting the following error

    Invalid version specified after -v flag: 2c -c public 192.168.2.162 SNMPv2-SMI::enterprise s.3.1.1

    here is the python code i am using
    Code:
    from subprocess import Popen
    Popen(['snmptrap', '-v 2c -c public 192.168.2.162 SNMPv2-SMI::enterprises.3.1.1'])
    When i test the same command from the shell like this it works
    snmptrap -v 2c -c public 192.168.2.162 SNMPv2-SMI::enterprise s.3.1.1

    I tried to close the space between v and 2c so its like this -v2c but i still get the error.

    I will appreciate it very much if you can help me correct this or point out to me what i am doing wrong.

    Thanks
    Kaf
  • kaf3773
    New Member
    • Jan 2012
    • 20

    #2
    Hi,

    I got it to work and this is the code i used
    Code:
    import subprocess
    from subprocess import Popen, PIPE
    path = "-v 2c -c public 192.168.2.162 '' SNMPv2-SMI::enterprises.3.1.1"
    Popen(['/opt/csw/bin/snmptrap', '%s' % path], shell=True, stdout=PIPE, stderr=subprocess.STDOUT)
    If someone also has a better way to do it i will appreciate that as well.
    Thanks

    Comment

    Working...