简单优化一下威联通机械硬盘独立休眠脚本

各位大佬珠玉在前,但是在使用的时候发现偶尔新增了硬盘的情况下硬盘设备路径变动,比如从 /dev/sdb 变成了 /dev/sda,一般增删硬盘之后可能出现这种问题。为此略微修改了一下脚本,让脚本自己去找机械硬盘是哪块,解决手动写硬盘路径的问题
以下是 disconnect_internal_raid.sh:
#!/bin/bash
for file in /sys/block/sd*/queue/rotational; do
value=$(cat "$file")
if [ "$value" -eq 1 ]; then
dev_file=$(echo "$file" | sed 's//sys/block///dev//' | sed 's//queue/rotational$//')
echo "Device path: $dev_file"
mdadm /dev/md9 --fail "${dev_file}1"
mdadm /dev/md13 --fail "${dev_file}4"
fi
done
以下是 rebuild_internal_raid.sh:
#!/bin/bash
for file in /sys/block/sd*/queue/rotational; do
value=$(cat "$file")
if [ "$value" -eq 1 ]; then
dev_file=$(echo "$file" | sed 's//sys/block///dev//' | sed 's//queue/rotational$//')
echo "Device path: $dev_file"
mdadm /dev/md9 --re-add "${dev_file}1"
mdadm /dev/md13 --re-add "${dev_file}4"
fi
done
作者声明本文无利益相关,欢迎值友理性交流,和谐讨论~

值友9144903293
校验提示文案
值友9144903293
校验提示文案