excelおじさん貼り付けようですぐに作る必要があったので雑ですが
server_list
domain.jp:www.domain.jp
nc_to_csv.sh
nc_to_csv.sh
#!/bin/bash
#set -x
SERVER_LIST="./server_list"
CMD="nc -w 0.1 -i 0.01 -vz"
PORT=(22 25 80 443)
CMD02="ping -w 0.1 -c 1 -t 1"
RESULT_FILE="/tmp/nc.csv"
if [ -f ${RESULT_FILE} ]; then
rm ${RESULT_FILE}
fi
for LIST in $(cat ${SERVER_LIST}); do
for i in "${PORT[@]}"; do
RECORD=$(echo ${LIST} | awk -F":" '{print $1}')
SERVER=$(echo ${LIST} | awk -F":" '{print $2}')
${CMD} ${SERVER} ${i} 2>/dev/null
if [ $? = 0 ]; then
RESULT+=("YES")
elif [ $? = 1 ]; then
RESULT+=("NO")
else
RESULT+=("fail")
fi
done
${CMD02} ${SERVER} 1>/dev/null
if [ $? = 0 ]; then
RESULT+=("YES")
elif [ $? = 1 ]; then
RESULT+=("NO")
else
RESULT+=("fail")
fi
#echo "${SERVER} ${RESULT[@]}"
RESULT_COMMA=$(echo "${RESULT[@]}" | sed -e 's/\ /\,/g')
echo "${LIST},${RESULT_COMMA}" >> ${RESULT_FILE}
RESULT=()
done
実行
$ ./portcheck.sh
13.115.109.xx NO YES NO NO NO
54.64.135.xx NO NO NO NO NO