-
Notifications
You must be signed in to change notification settings - Fork 0
/
pingGoogleTranslateIp.sh
executable file
·80 lines (77 loc) · 2.36 KB
/
pingGoogleTranslateIp.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/bash
. /etc/profile
parm_path=$(cd `dirname $0`; pwd)
cd $parm_path
rm ips.txt
rm activeip.txt
wget --no-check-certificate https://unpkg.com/@hcfy/google-translate-ip/ips.txt 2>&1
#以此往下到下个------------线注释部分为多线程筛选可用节点部分
start_time=`date +%s` #定义脚本运行的开始时间
success() {
if ping -c 3 $i >/dev/null #定义一个函数ping成功一次则显示success
then
echo -e "\033[32;1m$i Ping is success\033[0m"
echo "$i translate.googleapis.com" >> activeip.txt
echo "$i translate.google.com" >> activeip.txt
else
echo -e "\033[31;1m$i Ping is failure\033[0m"
fi
}
#线程数
thread_num=10
#管道文件名称,这里使用随机数加pid
fifo_file="/tmp/$RANDOM$$.fifo"
mkfifo "$fifo_file"
#定义文件描述符指向这个管道文件
exec 9<>"$fifo_file"
rm -fr "$fifo_file"
#初始化大小
for ((i=0;i<${thread_num};i++));do
echo
done >&9
for i in `cat ips.txt`
do
read -u9
{
success
sleep 1
} &
echo "">&9
done
wait
stop_time=`date +%s` # 定义脚本运行的结束时间
echo "多线程ping用时:`expr $stop_time - $start_time`s"
date=$(date "+%Y-%m-%d %H:%M:%S")
echo "# GoogleTranslateIp:""$date 日更新!" > README.md
if [ -s activeip.txt ]
then
while true;
do
git init
git add ./
git commit -m "$date"
git branch -M main
git remote set-url origin https://[email protected]/hebe061103/GoogleTranslateIp.git
result=`git push -u origin main`
if echo "$result" | grep -e "set up to track remote branch";then
date=$(date "+%Y-%m-%d %H:%M:%S")
echo --$date-- "------------------------同步到github成功-------------------------" |tee -a /tmp/pingGoogleTranslateIp.log
break
else
let num++
date=$(date "+%Y-%m-%d %H:%M:%S")
echo --$date-- "------------------------同步失败,开始进行第$num次重试-------------------------" |tee -a /tmp/pingGoogleTranslateIp.log
sleep 10
if [ $num -eq 10 ];then
date=$(date "+%Y-%m-%d %H:%M:%S")
echo --$date-- "------------------------重试$num次失败,故障退出-------------------------" |tee -a /tmp/pingGoogleTranslateIp.log
break
fi
fi
done
fi
#清除日志内容
a=$(grep -c "" /tmp/pingGoogleTranslateIp.log)
if [ $a -gt 200 ]; then
rm /tmp/pingGoogleTranslateIp.log
fi