wget and return value

Technical issues/questions of an intermediate or advanced nature.
User avatar
Rava
Contributor
Contributor
Posts: 5416
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.01 x86_64 + 4.0 i586
Location: Forests of Germany

wget and return value

Post#1 by Rava » 29 Aug 2023, 08:43

Using this template

Code: Select all

wget -c "Valid-URL" -O "whatever 1.extention" \
 && notify-send -i info -t 0 "Downloading 1" "finished" \
  || notify-send -i error -t 0 "Downloading 1" "failed"
made me realize when I manually abort one such downloads with ctrl+c I still get neither the

Code: Select all

notify-send -i info -t 0 "Downloading 1" "finished"

result served nor this

Code: Select all

notify-send -i error -t 0 "Downloading 1" "failed"
I presume I need to add such forceful exits into my script, but how?
I only know of trapping ctrl+c and others and creating a function that is used (usually for temp files deletions and such) when e.g. ctrl+c was pressed.
But that would not give me any info which file name exactly was aborted but only a rather generic error, like so

Code: Select all

function error_exit () {
notify-send -i error -t 0 "Downloading failed due to script interruption." \
"Check files manually!"
}
The only way to also get the file name (or when its a numbered list from say

Code: Select all

whatever 01.extention
whatever 01.extention
up to
whatever 22.extention
01 to 22 would me using a parameter that stores the current file number and use that parameter in the error_exit function.
But that creates too much complexity and thus too much risk of bugs to even consider.
Cheers!
Yours Rava

User avatar
Ed_P
Contributor
Contributor
Posts: 8374
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 5.01 ISO
Location: Western NY, USA

wget and return value

Post#2 by Ed_P » 29 Aug 2023, 15:13

Maybe your wget script could list the name of each file as it is being downloaded so ctrl+c would know what is getting cancelled.
Ed

User avatar
Rava
Contributor
Contributor
Posts: 5416
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.01 x86_64 + 4.0 i586
Location: Forests of Germany

wget and return value

Post#3 by Rava » 29 Aug 2023, 15:44

^
wget itself does that, so you see what is currently downloaded.
then, when you manually kill the script via ctrl+c it should be obvious which file was currently downloaded.
Also, if the hosting server supports that action, wget would set the time stamp of the downloaded file to the same date/time as the server version (just like yt-dlp does), so when you see a too small file with a very recent time stamp it is obvious which was the cancelled download.
Usually resuming such a download will still result in an error free file.

The resuming part is what wget -c is about.
Cheers!
Yours Rava

User avatar
Ed_P
Contributor
Contributor
Posts: 8374
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 5.01 ISO
Location: Western NY, USA

wget and return value

Post#4 by Ed_P » 29 Aug 2023, 17:26

Rava wrote:
29 Aug 2023, 15:44
wget itself does that, so you see what is currently downloaded.
If that's the case how are you having a problem knowing what file was cancelled when you did your ctrl+c? :%)
Ed

User avatar
Rava
Contributor
Contributor
Posts: 5416
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.01 x86_64 + 4.0 i586
Location: Forests of Germany

wget and return value

Post#5 by Rava » 29 Aug 2023, 17:28

Ed_P wrote:
29 Aug 2023, 17:26
If that's the case how are you having a problem knowing what file was cancelled when you did your ctrl+c?
A program can crash even without Ctrl+C, that one was the most easy example that everyone can relate to.
Cheers!
Yours Rava

Post Reply