On Fri, Oct 30, 2020 at 05:44:07PM +0100, MN wrote:
> In other words; if the size of the file hasn't changed in 10 minutes
> then it's done.
> The problematic part is that I don't know how to compare it with an
> older measurement.
size=$(wc -c < "$file")
That's actually the easy part. The harder part is checking the elapsed
time since the last increase in size. I'd use SECONDS for this.
Totally untested, so consider putting "echo" in front of the sudo
shutdown command when you test it. Hint: lowering the times makes
testing quicker. You could even move the two magic constants (30 and
600) into variables at the top of the script to make finding them
easier.
#!/bin/bash
file=/wherever/video.mp4
oldsize=0
while sleep 30; do
size=$(wc -c < "$file")
if ((size > oldsize)); then
oldsize=$size
SECONDS=0
continue
fi
# If we reach this point, size and oldsize are the same, so see how long
# it has been since the last time we reset the SECONDS variable.
if ((SECONDS > 600)); then
break
fi
done
# If we break out of the loop, it means the file's size hasn't changed
# in a while, so shut down the system.
sudo shutdown -h now