You are not logged in.

#1 2016-10-29 05:05:18

HaloSlayer255
Member
Registered: 2015-02-11
Posts: 29

[SOLVED] Shutdown script after large downloads, is it possible?

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

#2 2016-10-29 05:09:32

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: [SOLVED] Shutdown script after large downloads, is it possible?

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.


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#3 2016-10-29 12:51:44

svnset
Member
Registered: 2016-07-31
Posts: 75

Re: [SOLVED] Shutdown script after large downloads, is it possible?

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

#4 2016-10-31 02:44:55

HaloSlayer255
Member
Registered: 2015-02-11
Posts: 29

Re: [SOLVED] Shutdown script after large downloads, is it possible?

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

#5 2016-11-01 03:11:05

mpan
Member
Registered: 2012-08-01
Posts: 1,208
Website

Re: [SOLVED] Shutdown script after large downloads, is it possible?

Is electricity that expensive? smile

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

#6 2016-11-01 04:14:29

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,792

Re: [SOLVED] Shutdown script after large downloads, is it possible?

mpan wrote:

Is electricity that expensive? smile

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

Online

#7 2016-11-01 04:21:43

HaloSlayer255
Member
Registered: 2015-02-11
Posts: 29

Re: [SOLVED] Shutdown script after large downloads, is it possible?

mpan wrote:

Is electricity that expensive? smile

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.

ewaller wrote:

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 wink

Will check back after testing thanks again all,
HaloSlayer255

It works, thanks again!

Last edited by HaloSlayer255 (2016-11-01 13:54:38)

Offline

Board footer

Powered by FluxBB