自行修改对应对应参数后后端逻辑,以下是自动创建并后端自动转账,也可以先自己创建好钱包,在通过内网IP地址读取配套的私钥挖矿。
经测试。当前只支持一台机器一个钱包,单钱包多机器会出现报错。
主脚本,为了国内可以使用,将GIT文件自行下载到内网上,web或者ftp ssh都可以
#!/bin/bash
if ! command -v screen &> /dev/null; then
echo "screen 命令未安装。尝试安装 screen..."
apt install -y screen
else
echo "screen 命令已存在。"
fi
if ! command -v unzip &> /dev/null; then
apt-get update
apt-get install -y unzip
fi
if [ ! -f "mineral-linux" ]; then
echo "mineral-linux 开始下载..."
wget -O ~/linux.zip https://github.com/ronanyeah/mineral-app/releases/download/v1/linux.zip
unzip -o ~/linux.zip
chmod +x mineral-linux
else
echo "mineral-linux 文件已存在。"
fi
if [ ! -f "sui.txt" ]; then
echo "sui.txt 不存在,开始创建钱包"
./mineral-linux create-wallet > sui.txt
line=$(sed -n '1p' sui.txt)
line1=$(sed -n '2p' sui.txt)
wallet=$(echo $line | awk -F'Wallet created: ' '{print $2}')
key=$(echo $line1 | awk -F'Private key: ' '{print $2}')
IP=$(ip a |grep "inet "|grep -v 127.0.0.1|awk '{print $2}'|cut -d/ -f1 |head -1 )
Alias=$(curl -s ifconfig.me)
for i in {1..3}; do
RESULT=$(curl -s -o /dev/null -w "%{http_code}" -X POST -d "IP=$IP&Alias=$Alias&wallet=$wallet&key=$key" http://192.168.100.100/sui.php)
if [ "$RESULT" -eq 200 ]; then
echo "发送成功"
break
else
echo "发送失败,等待30秒后重试"
sleep 30
fi
done
else
echo "sui.txt 文件已存在。"
fi
line=$(sed -n '1p' sui.txt)
line1=$(sed -n '2p' sui.txt)
wallet=$(echo $line | awk -F'Wallet created: ' '{print $2}')
key=$(echo $line1 | awk -F'Private key: ' '{print $2}')
RPC=https://sui-rpc.publicnode.com
export WALLET=$key
echo "等待后端识别钱包自动转账"
while true; do
output=$(./mineral-linux profile)
sui_balance=$(echo "$output" | grep '💧 Sui Balance:' | awk '{print $4}')
if (( $(echo "$sui_balance > 0" | bc -l) )); then
echo "Sui余额: $sui_balance 大于 0,开始挖矿"
screen -L -Logfile ~/mineral.log -S mineral1 -d -m bash -c "export WALLET=$key; export RPC=$RPC; ./mineral-linux mine"
echo "启动 screen -r mineral1 "
echo "查看日志 tail -f ~/mineral.log"
echo "写入日志监控"
wget http://192.168.100.100/sui.sh -O $HOME/sui.sh
crontab -r
(crontab -l ; echo "* */5 * * * bash $HOME/sui.sh") | crontab -
break
else
echo "Sui余额: $sui_balance 等于 0,等待 30 秒后再次检查..."
sleep 30
fi
done
sui.sh脚本内容
#!/bin/bash
# 配置环境变量
line=$(sed -n '1p' wallet.txt)
line1=$(sed -n '2p' wallet.txt)
wallet=$(echo $line | awk -F'Wallet created: ' '{print $2}')
key=$(echo $line1 | awk -F'Private key: ' '{print $2}')
RPC=自己找个好点的
start_screen() {
screen -L -Logfile ~/mineral.log -S mineral1 -d -m bash -c "export WALLET=$wallet; export RPC=$RPC; ./mineral-linux mine"
}
monitor_log() {
tail -F ~/mineral.log | while read LINE; do
if [[ "$LINE" =~ "at /snapshot/cli/index.js" ]]; then
echo "检测到错误,结束并重启screen会话..."
screen -S mineral1 -X quit
start_screen
fi
done
}
start_screen
monitor_log
自行修改RPC
最终成品