hpool-chia-挂机脚本

1.查询并删除目录下某类文件

2.查询磁盘数量

3.执行挂盘脚本

4创建miner会话挂机

======================================start.sh==========================================

#!/bin/bash

# 删除 /home/test 目录下的mount-info.log 文件
find /home/test -type f -name "mount-info.log" -delete

#查询识别盘数量
diskcount=$(lsblk -l -o Name |grep -E "sd[a-z]*[a-z]$"|wc -l )

 #输出挂盘数量
 echo "total load disk number $disk-count" >>/home/tuoluo/mount-info.log

# 执行 auto-mount.sh 脚本以 root 权限
sudo  bash -c " cd /home/test && ./auto-mount.sh“

# 检查auto-mount.sh 是否成功执行,如果成功,则执行 5.sh 脚本
if [ $? -eq 0 ]; then

     #查询地址数量
     plot-count=$(find /mnt -type f -name "*.fpt"| wc -l)

     #输出地块数
     echo "total load plot number $diskcount" >>/home/tuoluo/mount-info.log

     #执行miner
     screen -dmS miner sudo bash -c " cd /home/test && ./5.sh"
     
     screen -x miner
  
else
    echo "auto-mount.sh 执行失败,无法继续执行 miner"
fi

 ============================auto-mount.sh=====================================

 
#!/bin/bash

### BEGIN INIT INFO
# Provides:          mount.sh
# Required-start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts mount 
# Description:       starts mount 
### END INIT INFO

# 开机挂载硬盘
# 扫描可用的磁盘设备
for device in $(lsblk -r -o NAME | grep -E "sd[a-zA-Z0-9/]+[0-9]$");
do
  # 检查设备是否已经挂载
  if ! grep -qs "/dev/$device" /proc/mounts; then
    # 确保挂载点存在,如果不存在就创建
    mount_point="/mnt/$device"
    mkdir -p "$mount_point"
    
    # 尝试挂载设备到挂载点
    mount "/dev/$device" "$mount_point"
    
    # 检查挂载是否成功
    if [ $? -eq 0 ]; then
      echo "成功挂载设备 /dev/$device 到 $mount_point"
      echo "/dev/$device $mount_point auto defaults 0 0" | sudo tee -a /home/mount.log
    else
      echo "无法挂载设备 /dev/$device 到 $mount_point,删除挂载点"
      rmdir "$mount_point" # 删除挂载失败的目录
    fi
  else
    echo "设备 /dev/$device 已经挂载"
  fi
done

# 所有挂载完成后输出退出码 0(成功)
exit 0

======================================拆分文件路径,每100个文件夹一组============================

#!/bin/bash

#  create scan path

find /home/test -type f -name "plot*.txt" -delete

index=0
find /mnt -type d -print0 | while IFS= read -r -d ''; do
  txt_count=$(find "$REPLY" -maxdepth 1 -name '*.plot' -type f | wc -l)
  if [[ $txt_count -gt 0 ]]; then
   # resultstr="$resultstr -r -d $REPLY"
   #运算符前加 expr
    i=$( expr $i + 1)
    tmp=$(expr $i / 100)
    echo "==========this is third line $tmp============"
    printf " - %s\n" "$REPLY" | tee -a /home/test/plot_dir_output_$tmp.txt
   # echo $resultstr
  fi
done

  

======================================5.sh===================================================

#!/bin/bash
 
# 创建并启动 Screen 会话,使用 root 权限执行/home/test/1下的命令
chmod +x  /home/test/1/1
screen -dmS session1 sudo bash -c "cd /home/test/1 && ./1"
 
chmod +x  /home/test/2/2
# 创建并启动 Screen 会话,使用 root 权限执行/home/test/2下的命令
screen -dmS session2 sudo bash -c "cd /home/test/2 && ./2"
 
chmod +x  /home/test/3/3
# 创建并启动 Screen 会话,使用 root 权限执行/home/test/3下的命令
screen -dmS session3 sudo bash -c "cd /home/test/3 && ./3"
#screen -x  session3

  

  

posted @ 2024-04-11 14:32  zhihua  阅读(53)  评论(0)    收藏  举报