- 论坛徽章:
- 12
|
本帖最后由 sync_1521 于 2015-06-04 11:34 编辑
脚本如下: cat /home/clouder/cbin/script/cron/iptable_save.sh- #!/bin/bash
- ip_list="192.168.1.10..220,192.168.2.10..220"
- iptables_route_path=/home/clouder/temp
- day=`date +%Y%m%d`
- cat /dev/null >/tmp/iplist
- for line in $(echo ${ip_list}|awk -F "," 'BEGIN{OFS="\n"}{$1=$1;print $0}')
- do
- ipPre=`echo $line | cut -d '.' -f -3`
- ipStart=`echo $line | cut -d '.' -f 4`
-
- if [[ $line == *..* ]]; then
- ipEnd=`echo $line | cut -d '.' -f 6`
- for ((j=$ipStart; j<=$ipEnd; j++))
- do
- echo $ipPre.$j >>/tmp/iplist
- done
- else
- ipEnd="$ipStart"
- echo $ipPre.$ipStart >>/tmp/iplist
- fi
- done
- record()
- {
- osinfo=$(ssh $1 'cat /etc/issue' |tr '[A-Z]' '[a-z]'|grep -oP 'opensuse|centos|ubuntu')
- case $osinfo in
- opensuse)
- iptablessave="/usr/sbin/iptables-save"
- ;;
- centos|ubuntu)
- iptablessave="/sbin/iptables-save"
- ;;
- *)
- echo "os system is not support in this script"
- ;;
- esac
- ssh $1 "netstat -rn" 2>&1>>$iptables_route_path/$1_${day}_iptable_route
- echo "##################################################" >>$iptables_route_path/$1_${day}_iptable_route
- ssh $1 "sudo $iptablessave" 2>&1>>$iptables_route_path/$1_${day}_iptable_route
- }
- MAX_THREAD_NUM=50
- tmp_fifo_file=/tmp/$.fifo
- mkfifo "$tmp_fifo_file"
- exec 9<>"$tmp_fifo_file"
- rm "$tmp_fifo_file"
- for ((i=0;i<$MAX_THREAD_NUM;i++))
- do
- echo
- done >&9
- set -x
- while read line
- do
- {
- read -u 9
- {
- destIp=$line
- echo $line
- record $destIp
- echo >&9
- }&
- }
- done </tmp/iplist
- set +x
- wait
- exec 9>&-
- cd $iptables_route_path
- rm *${day}_iptable_route
复制代码 我发现每次执行只执行了51台机器,而我实际IP列表有400多台机器,求指点,多谢!
但我将record $destIp 注释后,又能全部执行,百思不得其解。。莫非这种多线程只支持本地命令,不支持远程命令(ssh)??
|
|