현재 특정 형태의 출력 메시지 표시에 대한 코드를 작성 중이며 함수가 호출 될 때 변수에 대한 값을 설정하는 데 문제가 있습니다. 또한 코드가 실행될 때마다 오류 메시지 "op : command not found"가 발생합니다.
다음은 예상 출력입니다.
RIU 1 is online/offline
RIU 2 is online/offline
RIU 1 is online/offline
RIU 2 is online/offline
RIU 1 is online/offline
RIU 2 is online/offline
RIU 1 is online/offline
RIU 2 is online/offline
이것은 내가 얻는 출력입니다.
line 10: op: command not found
RIU is online/offline
line 10: op: command not found
RIU is online/offline
line 10: op: command not found
RIU is online/offline
line 10: op: command not found
RIU is online/offline
line 10: op: command not found
RIU is online/offline
line 10: op: command not found
RIU is online/offline
line 10: op: command not found
RIU is online/offline
line 10: op: command not found
RIU is online/offline
내 스크립트는 다음과 같습니다.
#!/bin/bash
echo "Ping Test for RIU"
read -p "Enter the number of RIU : " x
echo -e "Initiating RIU Ping Test\n"
a=101
y=x*2
for ((i=1; i<=y; i++))
do
op i
if ping -c1 -W1 192.168.1."$a" 1>/dev/null
then
echo "RIU "$b" is online"
else
echo "RIU "$b" is offline"
fi
let "a+=1"
done
echo -e "\nRIU Ping Test Complete"
op()
{
c = $i
d = expr $c % 2
if [ $d -eq 1]
then
b = 1
else
b = 2
fi
}
내가 언급 한 맞춤법 검사기를 통해 스크립트를 통과 한 후에는 유망 해 보이지만 완전히 작동한다고 보장하지는 않습니다.
#!/bin/bash
op()
{
c=$i
d=$((c % 2))
if [[ $d -eq 1 ]]
then
b=1
else
b=2
fi
}
echo "Ping Test for RIU"
read -p "Enter the number of RIU : " x
echo -e "Initiating RIU Ping Test\n"
a=101
y=$((x*2))
for ((i=1; i<=y; i++))
do
op "$i"
if ping -c1 -W1 192.168.1."$a" 1>/dev/null
then
echo "RIU "$b" is online"
else
echo "RIU "$b" is offline"
fi
a=$((a+1))
done
echo -e "\nRIU Ping Test Complete"
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다