Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
monitorio - Bash function to monitor the size of a file on disk
# Show write speed for file or directory
# Optional second parameter to set the check interval in seconds, defaults to 20
monitorio () {
target="$1"
interval=${2:-"20"}
echo -e "Checking every ${interval} seconds"
size=$(du -ks "$target" | awk '{print $1}')
firstrun="1"
echo ""
while [ 1 ]; do
prevsize=$size
size=$(du -ks "$target" | awk '{print $1}')
#size=$(ls -l "$1" | awk '{print $5/1024}')
kb=$((${size} - ${prevsize}))
kbmin=$((${kb}* (60/${interval}) ))
kbsec=$((${kbmin}/60))
kbhour=$((${kbmin}*60))
if [ $firstrun -ne 1 ]; then
echo -e "\e[1A $target changed ${kb}KB ${kbsec}KB/sec ${kbmin}KB/min ${kbhour}KB/hour size: ${size}KB"
fi
firstrun=0
sleep $interval
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.