작성
·
160
0
#!/bin/bash
##v.2.0
export IP1="0"
export IP2="0"
export IP3="0"
export DATE=$(date +"%F")
PS3="Select the option "
select char in "1, Check IP" "2, IP List" "3, Exit" #"4"#
do
case $char in
1*) read -p "Enter IP xxx.xxx.xxx. > " -t 20 IP1
read -p "Enter start IP xxx > " -t 20 IP2
read -p "Enter last IP xxx > " -t 20 IP3
echo -e "\033[32;1m"IP Checking!"\033[0m"
while [[ $IP2 -lt $IP3 ]]; do
ping -c 1 -w 1 $IP1$IP2 > /dev/null
if [[ $? == 0 ]]; then
echo $IP1$IP2 is In-use. >> /tmp/ip_list_$DATE ;
else
echo $IP1$IP2 is Dead or Available. >> /tmp/ip_list_$DATE ;
fi
IP2=$(($IP2+1))
done
echo -e "\033[31;1m"IP Check well done! please verify IP"\033[0m" ;;
2*) grep -q Avail* 2> /dev/null < /tmp/ip_list_$DATE
if [[ $? == 0 ]]; then
grep -r --color=always Available /tmp/ip_list_$DATE | sort -u
else
echo -e "\033[31;3m"There is no available IP"\033[0m"
fi ;;
3*) echo "Good bye"; exit 0 ;;
#4*) echo "You choose not yet menu it will be add section coming soon asap" ;;
*) echo "!!Error select correctly number!!"
esac
done
[root@hlldvc ddrec]# ./ipcheck.sh
1) 1, Check IP
2) 2, IP List
3) 3, Exit
Select the option
답변 1
0
안녕하세요. gorogong 님
아래처럼 하면 되지않을까요?
select char in "Check IP" "IP List" "Exit" #"4"#
원하시는 답변이 아닐 경우 다시 질문올려주세요.
답변 주신대로 변경 이후
"Check IP") read -p "Enter IP xxx.xxx.xxx. > " -t 20 IP1
read -p "Enter start IP xxx > " -t 20 IP2
read -p "Enter last IP xxx > " -t 20 IP3
echo -e "\033[32;1m"IP Checking!"\033[0m"
echo -e " " > /tmp/ip_list_$DATE > /dev/null
while [[ $IP2 -lt $IP3 ]]; do
ping -c 1 -w 1 $IP1$IP2 > /dev/null
if [[ $? == 0 ]]; then
echo $IP1$IP2 is In-use. >> /tmp/ip_list_$DATE ;
else
echo $IP1$IP2 is Dead or Available. >> /tmp/ip_list_$DATE ;
fi
IP2=$(($IP2+1))
done
echo -e "\033[31;1m"IP Check well done! please verify IP"\033[0m" ;;
"IP List") grep -q Avail* 2> /dev/null < /tmp/ip_list_$DATE
if [[ $? == 0 ]]; then
grep -r --color=always Available /tmp/ip_list_$DATE
else
echo -e "\033[31;3m"There is no available IP"\033[0m"
fi ;;
"Exit") echo "Good bye"; exit 0 ;;
case 문 앞을 변경하니 정상적으로 작동합니다 감사합니다!