試圖獲取cyberghostvpn --status終端中顯示的輸出,No VPN connections found.或者是VPN connection found.
我試過| grep -x "No VPN connections found."$VPN_status 并收到錯誤。甚至不記得過去幾個小時我嘗試過的一切。感覺這是一個簡單的解決方案,但我只是想念它。這是代碼($index 是從未在此摘錄中列出的陣列中隨機選擇的):
VPN_status="$(cyberghostvpn --status)"
echo $VPN_status
if [[ $? == "No VPN connetions found." ]]; then
echo "Connecting to VPN."
cyberghostvpn --country-code $index --server-type traffic --openvpn --connect
else
echo "You are connected to the VPN already."
fi
這將回傳:
No VPN connections found.
You are connected to the VPN already.
uj5u.com熱心網友回復:
您正在檢查回傳代碼(一個數字)而不是文本。
這可能會起作用:
VPN_status="$(cyberghostvpn --status)"
echo $VPN_status
if [[ $VPN_status == "No VPN connetions found." ]]; then
echo "Connecting to VPN."
cyberghostvpn --country-code $index --server-type traffic --openvpn --connect
else
echo "You are connected to the VPN already."
fi
uj5u.com熱心網友回復:
在并非不合理的假設下,cyberghostvpn --status如果連接正常,則將退出代碼設定為零,您可以簡單地撰寫
if cyberghostvpn --status
then
echo You are connected
else
echo Trying to connect
....
fi
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/372396.html
