From 9a474e2bcbd65cb740866e413d1aa8c501201adb Mon Sep 17 00:00:00 2001 From: Lucas Possatti Date: Fri, 26 Jun 2015 20:46:52 -0300 Subject: [PATCH] Add 'trap' for SIG{HUP,INT,TERM} When one of these signals is received by the process, it will remove the file created by the interrupted 'wget' download. --- scrap_data.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scrap_data.sh b/scrap_data.sh index e77207a..d35e097 100755 --- a/scrap_data.sh +++ b/scrap_data.sh @@ -51,6 +51,12 @@ for line in $pokemon_images; do # Unescape HTML characters... Damn "Farfetch'd". pokemon_name=$(echo "$pokemon_name" | sed "s/'/'/") + # If wget is interrupted by a SIGINT or something, it will + # leave a broken file. Let's remove it and exit in case we + # receive a signal like this. + # Signals: (1) SIGHUP; (2) SIGINT; (15) SIGTERM. + trap "rm $scrap_folder/$pokemon_name.png; echo Download of $pokemon_name was cancelled; exit" 1 2 15 + echo " > Downloading '$pokemon_name' from '$pokemon_url' to '$scrap_folder/$pokemon_name.png' ..." wget "$pokemon_url" -O "$scrap_folder/$pokemon_name.png" -q done