Trying to query a ton of devices with a simple output (in this test case; model identification)
My code works fine when running individually; its when I attempt to parallelize it...errors occur
Script file named "get":
\#!/bin/bash
model="$(snmpbulkget -r1 -t1 -v2c -c test_comm $1 1.3.6.1.2.1.47.1.1.1.1.13 | grep -m1 STRING | sed 's/.*://' | sed 's/ "//' | sed 's/"//')" &&
echo "$1,$model"
Using a single test; works with no issue:
./get 10.23.50.117
10.23.50.117,N9K-C93108TC-EX
Trying to parallelize (even with just 10 processes):
xargs -d " " -P 10 --arg-file=check ./get
snmp_build: unknown failure
snmpbulkget: Error building ASN.1 representation (Can't build OID for variable)
Using the -L arg flag in xargs causes each IP in the list to be hit 10x instead of 10 IPs once each.
cat check_out | sort
10.12.0.1,NY-SW1
10.12.0.1,NY-SW1
10.12.0.1,NY-SW1
10.12.0.1,NY-SW1
10.12.0.1,NY-SW1
10.12.0.1,NY-SW1
10.12.0.1,NY-SW1
10.12.0.1,NY-SW1
10.12.0.1,NY-SW1
10.12.0.1,NY-SW1
10.12.0.4,NY-SW2
10.12.0.4,NY-SW2
10.12.0.4,NY-SW2
10.12.0.4,NY-SW2
10.12.0.4,NY-SW2
10.12.0.4,NY-SW2
10.12.0.4,NY-SW2
10.12.0.4,NY-SW2
10.12.0.4,NY-SW2
10.12.0.4,NY-SW2
10.14.14.8,CY-WAN-SW1
10.14.14.8,CY-WAN-SW1
10.14.14.8,CY-WAN-SW1
10.14.14.8,CY-WAN-SW1
10.14.14.8,CY-WAN-SW1
10.14.14.8,CY-WAN-SW1
10.14.14.8,CY-WAN-SW1
10.14.14.8,CY-WAN-SW1
10.14.14.8,CY-WAN-SW1
10.14.14.8,CY-WAN-SW1
Your problem is that of understanding the arguments to the "xargs" utility. You did not tell us what your "check" file looks like. When I try it with the correct arguments, it works:
% ./get 10.201.0.110
10.201.0.110,..System Bootstrap, Version 11.0(10c), SOFTWARE..Copyright (c) 1986-1996 by cisco Systems..
% ./get 10.1.120.142
10.1.120.142,BOOT_NORMAL
% cat check
10.201.0.110
10.1.120.142
% xargs -L 1 -P 10 --arg-file=check ./get
10.201.0.110,..System Bootstrap, Version 11.0(10c), SOFTWARE..Copyright (c) 1986-1996 by cisco Systems..
10.1.120.142,BOOT_NORMAL