Determine if download is occuring

fixit7

Member
Joined
Mar 4, 2019
Messages
63
Reaction score
18
Credits
55
I am trying to determine if a download is concurring in my download directory.

This is not working.

I also do not understand what lines #1 and #2 are doing.

Thanks

#!/bin/bash
# Estimates file usage
old=$(du -sh /home/andy/Downloads/)
while true; do
new=$(du -sh /home/andy/Downloads/)
if [ '$old -eq $new' ] ;
then
break
fi
1. old=$new
2. xdotool getactivewindow key Ctrl
sleep 5
done
 


This would be my updated version of that script.
Code:
#!/bin/bash
old=$(du -s $HOME/Downloads/)
while true; do
    new=$(du -s $HOME/Downloads/)
    if [ "$old" = "$new" ]; then
        break
    fi
    old="$new"
    xdotool getactivewindow key Ctrl
    sleep 5
done

The first line is tells Linux to use /bin/bash to interpret it instead of perl, python, awk, etc. which could also be there. The second (original) line was merely a comment.

I think it's better to use du -s than du -sh because the former prints a number, whereas the later prints something like "5.2G". Since it's rounded off, it might not change in 5 seconds.

It's better to use $HOME than your actual hard coded home directory.

The -eq operator is for numbers, but $old and $new contain other text, so you need a string comparison.

I don't know what the xdotool command is for, unless maybe it just keeps the window active and therefore the screensaver inhibited.

----------
You might need to move the sleep 5 command to the first line in the while loop. Otherwise, the initial value of $old and $new might be equal even though it's downloading. You might also want to increase the sleep time to allow for network hiccups.
 
thanks, I will study your code.

I do not think that this will help me.

old="$new"
xdotool getactivewindow key Ctrl
sleep 5

I would like to check for a download in progress and if not then do this.

echo "This script will suspend computer in 10 minutes if there is no mouse or keyboard activity."
while :; do
if (( $(xprintidle) >= 600000 )); then
systemctl suspend
fi
sleep 0.5
done
 
Last edited:


Latest posts

Top