Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

spawn argument evaluation/parsing

Help
2004-10-13
2013-05-02
  • Christopher
    Christopher
    2004-10-13

    I am stuck on what is a probably a very simple problem.  But I am stuck anyway...

    I am attempting to use expect to manipulate output from an snmp query.  Because the command <code>snmptable</code> has a rather long command line, I am trying to store the basic arguments in variables defined in the script header.

    What happens is when <code>spawn</code> is called to start <code>snmptable</code>, <code>snmptable</code> returns saying it does not understand the arguments.  It appears that spaces inside the argument/variable is causing problems.  Below is a simplified example of the script and the error.  Can you advise how to work around this situation while retaining the ability to store command arguments in variables?

    Many thanks!

    The Script:

    <pre>
    set SnmpTable "/opt/snmp-5.0.8/bin/snmptable"
    set BasicOpts  "-v 1 -c public"
    set MIBOpts    "-m ALL -M /proj/admin/etc/mibs"

    foreach Host $argv {
        spawn $SnmpTable $BasicOpts $MIBOpts $Host
        expect eof {}
    }
    </pre>

    The Error:
    <pre>
    spawn snmptable -v 1 -c public -m ALL -M /proj/admin/etc/mibs arctic NETWORK-APPLIANCE-MIB::dfTable
    Invalid version specified after -v flag:  1 -c public
    USAGE: snmptable [OPTIONS] AGENT
    </pre>

    As you can see the parts of the variable included in the BasicOpts are being grouped together such that the <code>snmptable</code> command thinks that the argument value to "-v" is "1 -c public"

    I've tried variations of 'join' and 'concat' and other weird combinations, but none work!  Arg!!!!