您的位置:首页 > 运维架构 > Shell

shell脚本-实现网站自动登录

2016-01-27 11:24 731 查看
login.sh: 登录网站,连接外网。

#!/bin/bash

uname=tanghongfei
passwd=123456

pass2=`echo -n $passwd | md5sum | cut -c9-24`

curl -H "Content-Type:application/x-www-form-urlencoded" -d "username=$uname&password=$pass2&drop=0&type=1&n=100" http://xxx.xxx.xxx.xxx/cgi-bin/do_login 2>/dev/null | grep error

if [ "$?" -eq "0" ]; then
exit -1
fi

exit 0


auto_login.sh: 实时监测,一旦下线,自动登录。

#! /bin/sh

interval=10

while (true)
do
result=`ping -w $interval www.baidu.com | grep '0 received'`
if [ "$result" != ""  ]; then
echo "network status: disconnected!!! relogin!!!"
./login.sh
else
echo "network status: connected!"
sleep 10
fi
done


备注:以上为Linux系统的实现方案。windows系统下没研究,装了个虚拟机来实现自动登录。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  shell 脚本