1

I have an SNMP pass script that I am running and, for some reason that I do not yet understand, additional uses of echo in the script causes the script to not execute. My precise issue right now is that I need to take a substring from a variable, REQ, and assign it to another variable. Below is a method that works in theory, but does not work in my situation due to the use of echo.

DGROUP_NODE=`echo $REQ | cut -d. -f3`

Is there another way to do this without disrupting whatever is reading the script? I have noticed that printf also tends to have the same issue, though less often. (This issue also prevents me from using echo or printf to debug my code...)

NOTES: When echo causes issues executing the script, no errors are returned (regarding the script). I only get No Such Instance currently exists at this OID which tells me that the script was not run, resulting in my OID tree not being built.

If I run the script outside of SNMP it works as expected.

2
  • RET != REQ, which is it? AND you'll almost always want to dbl-quote variable usage with echo, so echo "$REQ" may solve your problem. Good luck. Commented Jun 27, 2018 at 15:33
  • Should be REQ. I've tried adding quotes already, but the issue is with echo itself. The script works fine when run directly from terminal. Commented Jun 27, 2018 at 16:20

3 Answers 3

1

If, for example, I wanted just the PEN:

TREE=.1.3.6.1.4.1.8072.2.255
CHOP=.1.3.6.1.4.1.
PEN=${TREE##*$CHOP} # remove $CHOP from beginning (## = longest match from beginning)
PEN=${PEN%%.*} # keep everything before first period (%% = longest match from end)

Output:

8072

More about this method here: extract part of a string

Sign up to request clarification or add additional context in comments.

Comments

0

Use set +x then run again. I am sure the problem is that $RET is empty.

6 Comments

set +x in terminal before running?
When I do like so: $ set +x $ snmpwalk -v2c -cpublic localhost .1.3.6.1.4.1.(PEN) I get the same issue: MIB::module = No Such Instance currently exists at this OID
You should look into pipes and redirection in bash... that is going to stderr.
$REQ can't be empty because it is used in a case immediately after. The issue only occurs when adding additional echo statements AND running the script via SNMP. If I run the script outside of SNMP it works as expected.
Okay, will look into that.
|
0

Enclose echo with $ from your code like this:

DGROUP_NODE=$(echo $REQ | cut -d. -f3)

19 Comments

The code needs to work. The visual absence of echo is not sufficient.
I updated the code, sorry i had to test it. You are right.
Error: .snmp/pass_script_backup/passScript: 41: .snmp/pass_script_backup/passScript: 3: not found "41" is the line in the script, and "3" is the retrieved value from $REQ. It seems to be looking for a variable called "3"
registered debug token ucd-snmp/pass, 1 pcilib: Cannot open /proc/bus/pci pcilib: Cannot find any working access method. pcilib: pci_init failed Turning on AgentX master support. Error opening specified endpoint "" Server Exiting with code 1
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.