我有一个脚本可以在Cisco路由器的强制门户网站上自动连接和续订身份验证。它正在工作,看起来像这样:
while true
do
export ssid=$(/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I | awk '/ SSID/ {print substr($0, index($0, $2))}')
if [ "$ssid" != "SSID_NAME" ]; then # Not SSID_NAME
sleep 10
else # SSID_NAME Connected
if ping -c 1 google.com; then # Connected and everything is OK
sleep 5
else # There is no ping
curl -O http://auth.address/login.html
var=$(awk -F\" '/au_pxytimetag/{print $(NF-1)}' login.html)
curl -d "uname=guest&pwd=password&au_pxytimetag=$var" http://auth.address/login.html
fi
fi
done
但是我不想存储login.html页面并直接获取变量值,但是当我使用
时 var=$(awk -F\" '/au_pxytimetag/{print $(NF-1)}' http://auth.address/login.html)
我进入终端
awk: can't open file http://auth.address/login.html
我做错了什么?
答案 0 :(得分:1)
awk
无法获取该网页,如果您不想存储login.html
,可以直接将curl
的输出重定向到awk
,如下所示:
var=$(curl http://auth.address/login.html | awk -F\" '/au_pxytimetag/{print $(NF-1)}')