2015-04-03 83 views
-1

我遇到一個問題,我正在做一個bash腳本來檢查兩個IP地址。Bash腳本來檢查兩個IP地址

#!/bin/bash 
ping -c4 1.1.1.1 > /dev/null 
if [ $? != 1 ] 
then 
echo "Device1 is up" 
else 
echo "Device1 is down 

但是工作細,我想它來檢查第二個地址,然後即

#!/bin/bash 
ping -c4 1.1.1.1 > /dev/null 
if [ $? != 1 ] 
then 
echo "Device1 is up" 
else 
ping -c4 2.2.2.2 > /dev/null 
if [ $? != 1 ] 
then 
echo "Device2 is up" 
else 
echo "Device 2 is down" 
fi 

執行基於結果的命令,但它不工作,我得到

line 14: syntax error: unexpected end of file 
+2

請查看:http://www.shellcheck.net/ – Cyrus 2015-04-03 19:19:47

+1

縮進代碼並查看問題。 – Cyrus 2015-04-03 19:29:13

回答

1

你需要一個最終的「fi」來關閉第一個if ...

當你嵌套「if」語句(一個在另一箇中)y你必須有一個關閉「fi」爲每個如果。

+0

我知道這會是一件愚蠢的事,非常感謝 – Lurch 2015-04-03 19:22:28

+1

如果回答這個問題,請將其標記爲接受的答案。 – 2015-04-03 19:25:32