-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIP_CAS.sh
68 lines (57 loc) · 2.24 KB
/
IP_CAS.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
#connect internet and send ip
logfile=/home/pi/Desktop/ip.log
{
while true
do
# Login SUSTC CAS
echo ">----------------------------------------------------"
echo "Current time: `date '+%F %T'` "
URL=`curl --head baidu.com 2> /dev/null | grep "Location: http://enet.10000.gd.cn" | sed 's/Location: //'`
if echo $URL | grep -q "http"
then
DATE=`date "+%Y-%m-%d %H:%M:%S"`
URL=`echo "$URL" | sed 's/\r$//g'`
echo "[$DATE] Logging..."
FORM=`curl -L "${URL}" 2> /dev/null`
ACTION=`echo "$FORM" | grep "<form " | sed 's/.*action="\(.*\)" .*/\1/'`
LT=`echo "$FORM" | grep '<input type="hidden" name="lt" ' | sed 's/.*value="\(.*\)" .*/\1/'`
EXEC=`echo "$FORM" | grep '<input type="hidden" name="execution" ' | sed 's/.*value="\(.*\)" .*/\1/'`
DATA="username=youracount&password=yourpassword<=$LT&execution=$EXEC&_eventId=submit&submit=LOGIN"
RESULT=`curl -L --data "$DATA" "http://weblogin.sustc.edu.cn$ACTION" 2> /dev/null`
if echo $RESULT | grep -q "<h2>success"
then
echo "Success"
else
echo "Failed"
fi
fi
#check network again
TIMEOUT=15
SITE_TO_CHECK="open.163.com"
RET_CODE=`curl -I -s --connect-timeout $TIMEOUT $SITE_TO_CHECK -w %{http_code} | tail -n1`
if [ "x$RET_CODE" = "x200" ];
then
echo "Network OK, wait"
# get the IP address of eth0, e.g. "192.168.16.5"
# ETH0_IP_ADDR=`ifconfig eth0 | sed -n "2,2p" | awk '{print substr($2,1)}'`
# make log info
# echoecho "Current time: `date '+%F %T'` "Current time: `date '+%F %T'`. Enjoy it $ETH0_IP_ADDR"
# bypy.py upload /home/pi/Desktop/ip.log -v
# I don't known why it run bad :(
break
else
echo "Network not ready, wait..."
sleep 60s
fi
done
# get the IP address of eth0, e.g. "192.168.16.5"
ETH0_IP_ADDR=`/sbin/ifconfig eth0 | sed -n "2,2p" | awk '{print substr($2,1)}'`
#logfile=/home/pi/Desktop/ip.log
#Code in Windows will make erro!!!!!!!!!!!
#In shell if fi will be a {}
#what is {}in shell
#直接在shell中生存log文件,不过终端就不会显示了
#http://www.cnblogs.com/smbx-ztbz/p/4607007.html
#http://shumeipai.nxez.com/2014/03/18/let-raspberry-pi-ip-address-is-automatically-reported-to-the-mailbox.html
http://blog.csdn.net/lejuo/article/details/4040452