Quantcast
Channel: iT邦幫忙
Viewing all articles
Browse latest Browse all 15645

Freebsd Script 程式問題?

$
0
0
今天改了一個程一直怪怪的,底下程式是用來偵測某一網段,沒有關機的程式,在這行
SKIP_FILE="/data/www/no_down_pc/up_check_skip.txt"
裡面 up_check_skip.txt 是用來排除不要偵測的 ip ,問題就是出在這裡,如果在這個檔案裡面放了一個 ip ,假設就剛好是一開始的 ip 【10.56.66.1】,則因為
grep "${1}${IP}" "${SKIP_FILE}" >> /dev/null && break
整個程式就不會再掃描底下的 ip 了,break 會跳到最底下的 done ,有高手會改嗎?





#!/bin/sh
LOG_DIR='/data/www/no_down_pc/up_list'
LOG_FILE="${LOG_DIR}/`date +%Y%m%d`.html"
SKIP_FILE="/data/www/no_down_pc/up_check_skip.txt"
scan() {
UP_LIST=''
UP_LIST_HTML=''
COUNT=0
IP=${2}
while [ ${IP} -le ${3} ]; do
grep "${1}${IP}" "${SKIP_FILE}" >> /dev/null && break
UP=`/usr/local/bin/nbtscan -s' ' -q "${1}${IP}" | cut -d' ' -f2`
if [ "${UP}" = "<unknown>" ]; then
UP=`/usr/local/bin/nbtscan -s':' -q "${1}${IP}" | cut -d':' -f4 | cut -d'$' -f1`
fi
if [ -n "${UP}" ]; then
UP_LIST="${UP}(${1}${IP}) ${UP_LIST}"
UP_LIST_HTML="<FONT COLOR=BLUE>${UP}</FONT><FONT SIZE=-1>(${1}${IP})</FONT> ${UP_LIST_HTML}"
COUNT=$((${COUNT}+1))
fi
IP=$((${IP}+1))
done
echo "${4} 未關之電腦 ${COUNT} 部 ${UP_LIST}"
echo "<TR><TD>${4}<BR>${COUNT}\xb3\xa1</TD><TD>${UP_LIST_HTML}</TD></TR>" >> /tmp/up_check.html.$$
echo
}

NETWORK='10.56.66.'
IP_FROM='1'
IP_TO='10'
COMMENT='一樓'

scan "${NETWORK}" ${IP_FROM} ${IP_TO} "${COMMENT}"

Viewing all articles
Browse latest Browse all 15645

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>