Last active
April 16, 2023 11:07
-
-
Save einsteinx2/14a0e865295cf66aa9a9bf1a8e46ee49 to your computer and use it in GitHub Desktop.
monitorio - Bash function to monitor the size of a file on disk
This file contains 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
# 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