I think I have found a better solution. I implemented using make:
#!/usr/bin/make -f
IPFILE := ipfile
IPS:=$(foreach ip,$(shell cat $(IPFILE)),$(foreach sub,$(shell seq 1 1 254),$(ip).$(sub)))
all: $(IPS)
$(IPS):
SYSNAME=`snmpwalk -v2c -c public -t1 -r1 $@ sysName.0 2>/dev/null | awk '{ print $$NF }'`; \
SYSTYPE=`snmpwalk -v2c -c public -t1 -r1 $@ sysDescr.0 2>/dev/null | grep -o Linux`; \
if [ $$? -eq 0 ]; then \
echo "$$SYSNAME"; \
else \
echo "Processed $@"; \
fi
The first part of the IPs (e.g. 192.168.1) should be placed to ipfile. Then it generates all the IP addresses into the variable IPS
(Like 192.168.1.1 ... 192.168.1.254 ...).
These lines can be copied to e.g. test.mak
and add execute rights to the file. If one run it as ./test.mak
then it will process the IPs in IPS
one by one. But if it is run as ./test.mak -j 10
then it will process 10 IPs at once. Also it can be run as ./test.mak -j 10 -l 0.5
. It will run maximum 10 processes or until the system load reaches 0.5.