You are not logged in.
Hello all,
I am wondering if this scenario is possible to solve.
I sometimes download large files and will have the computer shutdown using "sudo shutdown -h +120" but that is too late, however if it's too early the downloads corrupt since it doesn't finish.
Is it possible to have a script setup that watches a network interface (enp0s7 for ethernet) and either initiates a shutdown if it is night or sleep during the day, when the computer is not downloading anything for the last 3 minutes. Ideally I would like this to occur at or after 10PM EST and the system must be up for at least 30 minutes before the shutdown occurs. I also use the palemoon browser if I'd need to monitor a program for the script to work.
Thanks all in advance,
HaloSlayer255
Last edited by HaloSlayer255 (2016-11-01 13:53:08)
Offline
Don't download the file with a browser, use curl in a script and then it is simple to initiate the shutdown once the download is complete; no guessing required.
Offline
Exactly, what you want to do is unnecessary complex. Just use curl and it is super easy. I guess if you need a download manager with advanced functionality you can realize it with aria etc. pretty easy too. Just spawn a child process and wait with your script for it to finish before you call shutdown.
After one has played a vast quantity of notes and more notes,
it is simplicity that emerges as the crowning reward of art. - Chopin
Offline
Will have to try that, come to think of it I use a diy curl script to update my hosts file.
When you mention a watching a child process something like: when $PID (value of curl script) = finished then shutdown now.
Thanks in advance,
HaloSlayer255
Offline
Is electricity that expensive?
Anyway, you may just watch if file is still growing:
#!/usr/bin/env bash
# Copyright © 2016 mpan; <https://mpan.pl/>; CC0 1.0
# Usage: thisScript TARGET_FILE
# Waits for TARGET_FILE to stop growing for at least 5 minutes and issues
# `shutdown -h now`.
# Solves: <https://bbs.archlinux.org/viewtopic.php?id=218893>.
# Adjust for your needs.
targetFile="$1"
shift
lastSize=$(stat -c %s "$targetFile")
prevSize=-1
until ((lastSize == prevSize)); do
sleep 300
prevSize=$lastSize
lastSize=$(stat -c %s "$targetFile")
done
shutdown -h now
Sometimes I seem a bit harsh — don’t get offended too easily!
Offline
Is electricity that expensive?
US$ 0.00025/Watt*hr
IOW, 25 cents to fill a typical laptop battery.
To put things in perspective...
or, US$21 to fill a (US$66,000) Tesla model S battery (which gets you about 430km [or 265 miles] in range), or about US$0.79/mile to operate
OTOH...
My Honda (US$17,000) Civic (33 Miles/Gallon) costs about US$0.077/mile to operate when fuel costs $2.55/gallon.
Edit: Fixed units (was power, not energy)
Last edited by ewaller (2016-11-01 14:14:24)
Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way
Offline
Is electricity that expensive?
Anyway, you may just watch if file is still growing:
#!/usr/bin/env bash # Copyright © 2016 mpan; <https://mpan.pl/>; CC0 1.0 # Usage: thisScript TARGET_FILE # Waits for TARGET_FILE to stop growing for at least 5 minutes and issues # `shutdown -h now`. # Solves: <https://bbs.archlinux.org/viewtopic.php?id=218893>. # Adjust for your needs. targetFile="$1" shift lastSize=$(stat -c %s "$targetFile") prevSize=-1 until ((lastSize == prevSize)); do sleep 300 prevSize=$lastSize lastSize=$(stat -c %s "$targetFile") done shutdown -h now
Thanks for this am testing now,
Not sure how much my computer costs to run but trying to minimize the cost where possible, and to try different approches to learn new things.
US$ 0.00025/Watt
IOW, 25 cents to fill a typical laptop battery.
To put things in perspective...
or, US$21 to fill a (US$66,000) Tesla model S battery (which gets you about 430km [or 265 miles] in range), or about US$0.79/mile to operate
OTOH...
My Honda (US$17,000) Civic (33 Miles/Gallon) costs about US$0.077/mile to operate when fuel costs $2.55/gallon.
Will have to calculate how much power everything uses
Will check back after testing thanks again all,
HaloSlayer255
It works, thanks again!
Last edited by HaloSlayer255 (2016-11-01 13:54:38)
Offline