cat find_host_port.sh
#!/bin/bash
unset service_name
unset service_port
service_list_path='/root/scripts/find_port/port_all.log'
service_list_line=$(cat ${service_list_path}|wc -l)
service_list_num=$((${service_list_line} -1 ))
service_name=($(awk '{print $1}' ${service_list_path}))
service_port=($(awk '{print $2}' ${service_list_path}))
main(){
for i in $(cat host_list.log)
do
> ${i}_port.log
echo "start ${i}"
for num in $(seq 0 ${service_list_num})
do
service_pro=$(ssh 192.168.100.${i} -C lsof -i:${service_port[${num}]}|wc -l)
if [ ${service_pro} -gt 0 ]
then
echo -e "${service_port[${num}]} \t ${service_name[${num}]}"
echo -e "${service_port[${num}]} \t ${service_name[${num}]}" >> ${i}_port.log
fi
done
done
}
main