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.
This commit is contained in:
Lucas Possatti
2015-06-26 20:46:52 -03:00
parent ed8fbb9f25
commit 9a474e2bcb

View File

@@ -51,6 +51,12 @@ for line in $pokemon_images; do
# Unescape HTML characters... Damn "Farfetch'd". # Unescape HTML characters... Damn "Farfetch'd".
pokemon_name=$(echo "$pokemon_name" | sed "s/'/'/") 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' ..." echo " > Downloading '$pokemon_name' from '$pokemon_url' to '$scrap_folder/$pokemon_name.png' ..."
wget "$pokemon_url" -O "$scrap_folder/$pokemon_name.png" -q wget "$pokemon_url" -O "$scrap_folder/$pokemon_name.png" -q
done done