read commands from STDIN if used as pipe
[dell-switch] / sw-snmpbulkwalk.sh
1 #!/bin/sh -e
2
3 # Usage: $0 [sw [oid]]
4
5 dir=/dev/shm/snmpbulkwalk/
6 if [ ! -d $dir ] ; then
7         mkdir $dir
8         ln -sv `pwd`/snmpbulkwalk/.git $dir/
9 fi
10
11 . ./snmp.conf
12
13 ext=""
14 if [ ! -z "$2" ] ; then
15         ext=".$2/"
16         test ! -d "$dir/$ext" && mkdir "$dir/$ext"
17 fi
18
19 ( test ! -z "$1" && echo $1 || ./sw-names ) | xargs -i sh -c \
20 "snmpbulkwalk -OX -v2c -Cc -c $COMMUNITY {} $2 | tee $dir/$ext{} && test -z "$ext" && cd $dir && git add $dir/$ext{} && git commit -m {} $dir/$ext{}" #| parallel 
21