Napsal: 01 srp 2025, 21:14
Se mnou nějak nekamarádí.
Vše, co potřebujete vědět o elektronice :-)
http://elektrobastlirna.cz/
Je to rozbitý. Když se skript pustí ve chvíli, kdy už se na disk nepřistupuje, tak se nikdy neuspí.asdf píše:To update last values asi může být v tom ifu, to je jedno. Klidně si to přehoď tam.
sd_time je zkratka spin down time. Tam je čas, kdy se ten disk naposledy uspal. To jsem potřeboval, aby se to neuspávalo každou sekundu, když disk není používán.
Kód: Vybrat vše
sd_time=0Kód: Vybrat vše
#!/bin/bash
# Usage: spindown sda 10 - spins down after 10 seconds
# Remember arguments.
disk=$1
timeout=$2
if test -z "$disk"
then
echo "Disk not defined." >&2
exit 1
fi
if test -z "$timeout"
then
echo "Timeout not defined." >&2
exit 1
fi
# Initial values.
last_read=0
last_write=0
last_discard=0
io_time=$(date '+%s')
spinning=1
# Loop.
while true
do
# Get current values.
time=$(date '+%s')
read=$(cat /sys/block/$disk/stat | awk '{ print $1 }')
write=$(cat /sys/block/$disk/stat | awk '{ print $5 }')
discard=$(cat /sys/block/$disk/stat | awk '{ print $12 }')
# Test if there is a change.
if test $read -ne $last_read -o $write -ne $last_write -o $discard -ne $last_discard
then
# Change found, update io_time.
if test $spinning = 0
then
# Was not spinning, just spinning up.
echo "Spinning up." >&2
fi
io_time=$time
spinning=1
fi
# Update last values.
last_read=$read
last_write=$write
last_discard=$discard
# Test if in idle too long.
time_idle=$(( $time - $io_time ))
echo "Idle for seconds: $time_idle" >&2
if test $time_idle -ge $timeout -a $spinning = 1
then
# Idle too long. Spin down.
echo "Spinning down." >&2
#hdparm -y /dev/$disk
spinning=0
fi
# Wait a second.
sleep 1
doneKód: Vybrat vše
2419 ? 00:00:00 power_button.sh
2420 ? 00:00:02 hdsleep.sh
2425 ? 00:00:00 power_button.sh
2426 ? 00:00:00 od
2427 ? 00:00:00 awk
2440 ttyS0 00:00:00 getty
2563 pts/1 00:00:00 bash
Kód: Vybrat vše
2419 ? 00:00:00 power_button.sh
2420 ? 00:00:02 hdsleep.sh
2440 ttyS0 00:00:00 getty
2563 pts/1 00:00:00 bash
6601 ? 00:00:00 power_button.sh
6602 ? 00:00:00 od
6603 ? 00:00:00 awk
14287 ? 00:00:00 sleep
14288 pts/1 00:00:00 psKód: Vybrat vše
readarray -d\ event < <(od -A n -t u2 -N 16 /dev/input/event0 | awk '{print $1, $2, $5, $6, $7}')Kód: Vybrat vše
od -A n -t u2 -N 16 /dev/input/event0 | awk '{print $1, $2, $5, $6, $7}' | readarray -d\ event