BEGIN{ # 请求接口数据 url = "http://uil.cbs.baidu.com/lbs/weather?resource=weather,pm2.5&city=%E5%8C%97%E4%BA%AC"; cmd = "curl -s " url; cmd | getline jsonStr; close(cmd); # 使用jq命令提取errno的值 cmd = "echo '" jsonStr "'|/usr/local/bin/jq '.errno'"; cmd |getline errno; close(cmd); # 检查字段值 if ( 0 == length(errno) || 0 != strtonum(errno) ) { print("API check failed"); } else { print("API status ok"); } }