Skip to content

Instantly share code, notes, and snippets.

@thinkycx
Created March 11, 2018 05:51
Show Gist options
  • Save thinkycx/2b4323353147e26ba9e97a6e3eee649e to your computer and use it in GitHub Desktop.
Save thinkycx/2b4323353147e26ba9e97a6e3eee649e to your computer and use it in GitHub Desktop.
bash script to connect to bupt gateway
#!/bin/bash
# author: thinkycx
# sudo ln -s ~/bupt-gateway.sh /usr/bin/bupt-gateway && source ~/.zshrc
user=XXX
password=XXX
URL="http://10.3.8.211"
HTTP_CODE=$(curl -s -IL $URL | head -n 1 | grep -o 200)
CODE=200
if [ $HTTP_CODE -eq 200 ];then
echo "Welcome to bupt!"
echo "connecting..."
HTTP_CODE2=$(curl $URL -d "DDDDD=$user&upass=$password&savePWD=0&0MKKey=" -D- -o/dev/null -s | head -n1 |grep -o 200)
if [ $HTTP_CODE2 -eq 200 ];then
echo "OK"
fi
else
echo "You are not in bupt!"
fi
@thinkycx
Copy link
Author

遇到了个curl 请求时的错误:

  • -I curl认为是HEAD请求
  • -d 认为是post请求,所以用-D 发post 请求后获取head,具体见脚本。

参考:http://www.jackxiang.com/post/6849/

其他:

  • grep -o 只输出匹配到的部分
  • curl -s slient模式
  • curl -I head请求

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment