一、脚本下载
wget --no-check-certificate -qO BWH.sh 'https://moeclub.org/attachment/LinuxShell/BWH.sh' && chmod a+x BWH.sh
二、运行命令
#前台运行 bash BWH.sh #后台运行 nohup bash BWH.sh >/dev/null 2>&1 &
三、脚本设置
这一步很关键,下载脚本之后,我们需要对脚本进行编辑,修改下面部分的关键数据。veid='1234560'; # VEID api_key='private_xxxxxxxxxxxxxxxxx'; # API KEY ToLocation='USCA_8'; # 目标机房代码. Timeout='150'; # API频率有限制,单位秒.每150秒运行一次.(不建议过低,否则面板报错.)至于如何修改我们可以通过下面命令来修改BWH.sh,或者直接把此文件从服务器下载下来直接用记事本修改后保存再上传到服务器。
vim BWH.sh
1、通过控制面板的API获取veid、api_key信息,如下图,报获取的信息填写到'1234560'、'private_xxxxxxxxxxxxxxxxx'引号内的内容。
2、获取ToLocation目标机房代码信息。首先同样通过控制面板进入到手动切换机房页面,可以入下图查看到需要的机房代码。
四、脚本代码预览
#!/bin/bash
veid='1234560';
api_key='private_xxxxxxxxxxxxxxxxx';
ToLocation='USCA_8';
Timeout='150';
# START
[[ -n "$veid" ]] || exit 1
[[ -n "$api_key" ]] || exit 1
[[ -n "$ToLocation" ]] || exit 1
[[ -n "$Timeout" ]] || exit 1
CurrentLocation='';
Token="?veid=${veid}&api_key=${api_key}";
API_URL="https://api.64clouds.com/v1/";
while [[ "$CurrentLocation" != "$ToLocation" ]]; do
CurrentLocation=$(wget --no-check-certificate -qO- "${API_URL}migrate/getLocations${Token}" |grep -o '"currentLocation":"[^"]*"' |cut -d'"' -f4)
echo "$(date +"[%Y/%m/%d %H:%M:%S]") ${CurrentLocation}";
if [ -n "$CurrentLocation" -a "$CurrentLocation" != "$ToLocation" ]; then
echo -n "${ToLocation}: "
wget --no-check-certificate -qO- "${API_URL}migrate/start${Token}&location=${ToLocation}" |grep -o '"message":"[^"]*"' |cut -d'"' -f4
else
break;
fi
sleep ${Timeout};
done
脚本出自:https://moeclub.org/2018/11/12/680/?v=791
赞(0)


