-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
Copy pathrevive.sh
46 lines (40 loc) · 1.56 KB
/
revive.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
#!/bin/bash
AUTOUPDATE=${AUTOUPDATE:-Y}
SENDTYPE=${SENDTYPE:-null}
TELEGRAM_TOKEN=${TELEGRAM_TOKEN:-null}
TELEGRAM_USERID=${TELEGRAM_USERID:-null}
WXSENDKEY=${WXSENDKEY:-null}
BUTTON_URL=${BUTTON_URL:-null}
LOGININFO=${LOGININFO:-N}
export TELEGRAM_TOKEN TELEGRAM_USERID BUTTON_URL
# 使用 jq 提取 JSON 数组,并将其加载为 Bash 数组
hosts_info=($(echo "${HOSTS_JSON}" | jq -c ".info[]"))
summary=""
for info in "${hosts_info[@]}"; do
user=$(echo $info | jq -r ".username")
host=$(echo $info | jq -r ".host")
port=$(echo $info | jq -r ".port")
pass=$(echo $info | jq -r ".password")
if [[ "$AUTOUPDATE" == "Y" ]]; then
script="/home/$user/serv00-play/keepalive.sh autoupdate ${SENDTYPE} \"${TELEGRAM_TOKEN}\" \"${TELEGRAM_USERID}\" \"${WXSENDKEY}\" \"${BUTTON_URL}\" \"${pass}\""
else
script="/home/$user/serv00-play/keepalive.sh noupdate ${SENDTYPE} \"${TELEGRAM_TOKEN}\" \"${TELEGRAM_USERID}\" \"${WXSENDKEY}\" \"${BUTTON_URL}\" \"${pass}\""
fi
output=$(sshpass -p "$pass" ssh -o StrictHostKeyChecking=no -p "$port" "$user@$host" "bash -s" <<<"$script")
echo "output:$output"
if echo "$output" | grep -q "keepalive.sh"; then
echo "登录成功"
msg="🟢主机 ${host}, 用户 ${user}, 登录成功!\n"
else
echo "登录失败"
msg="🔴主机 ${host}, 用户 ${user}, 登录失败!\n"
chmod +x ./tgsend.sh
export PASS=$pass
./tgsend.sh "Host:$host, user:$user, 登录失败,请检查!"
fi
summary=$summary$(echo -n $msg)
done
if [[ "$LOGININFO" == "Y" ]]; then
chmod +x ./tgsend.sh
./tgsend.sh "$summary"
fi