Last active
October 24, 2023 13:48
-
-
Save EldonMcGuinness/22704674e5cfef8c9996fb2f0d3ed5aa to your computer and use it in GitHub Desktop.
diskStandBy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
### | |
# How to use: Set this up as a Cron job and have it call at a regular interval. | |
# Example Cron time: */5 * * * * | |
### | |
#This needs to mach the name you gave the script in the unraid UI | |
SCRIPT_NAME=driveStandBy | |
# Remove the previous log | |
echo "" > "/tmp/user.scripts/tmpScripts/${SCRIPT_NAME}/log.txt" | |
for i in {b..z}; do | |
smartctl -i -n never /dev/sd$i | grep "Power mode " | sed 's/Pow.\+:\s\+\(.\+\)/\1/' >> "/tmp/${SCRIPT_NAME}_$i" | |
SB=$(cat /tmp/${SCRIPT_NAME}_$i | grep STANDBY | wc -l ) | |
ALL=$(cat /tmp/${SCRIPT_NAME}_$i | wc -l ) | |
if [ $ALL -lt 1 ]; then | |
continue | |
fi | |
printf "%s" "/dev/sd$i "; | |
echo "($SB/$ALL)*100" | bc -l | awk '{print substr($1,0,4)"%"}' | |
done; | |
echo Started On: $(stat -c %w "/tmp/${SCRIPT_NAME}_b") | |
echo Latest Run: $(stat -c %y "/tmp/${SCRIPT_NAME}_b") | |
exit 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment