I have a simple bash script to control Amazon AWS uploads and downloads. The uploading and downloading works fine. But sometimes, I have a poor internet connection and I want to cancel the AWS activity. However, when I click on the cancel button (zenity progress dialog) the AWS process continues and continues (for minutes)... The only way I can kill the AWS process is to go to the terminal and execute "killall -9 aws"
while [ "$repeat" -eq 0 ]; do
... setup code ...
aws s3 sync "$dir1" "$dir2" --region us-east-1 --output text --sse --delete | tr '\r' '\n' > "$last_log_file"
... error code analysis
done | zenity --progress --title="$title_text" --text="$msg" --pulsate --auto-close
killall -9 aws # <=== When I depress zenity 'cancel' ... this code never executes !!! (this code was added for debug)
I understand that when I depress the cancel pb that it should kill the process. Is there someway that I can force this to happen?
Thanks to Eric's reply, I now have a solution. The key was to add the '&' at the end of the zenity command in order to run a parallel process..
done | zenity --progress --title="$title_text" --text="$msg" --pulsate --auto-close &
And then to add some code to detect that the zenity pid has disappeared (because it was cancelled). Once it is detected that the zenity pid has gone, the killall command is used to kill aws
Some sample code:
zenity_pid="$(pidof zenity)"
while [ "$zenity_pid" != '' ]; do
echo "$(pidof zenity)" | grep -w "$zenity_pid"
if [ "$?" -eq 0 ]; then
sleep 2
else
killall -9 aws
zenity_pid=''
fi
done
wait
AWS returns an exit code 137 which means that the container received a SIGKILL signal