I'm working on a bash script, opening a yad window and keeping it opened until internet connection is present and then closing it.
It looks as follow:
#!/bin/bash
yad_wind1_id=""
yad_wind1_id_txt_str=""
NET_STATE=0
function test_net_connection()
{
(ping -c 1 www.google.com &>/dev/null)
XCODE=$?
if [ $XCODE == 0 ]; then
NET_STATE=1
else
NET_STATE=0
fi
}
function kill_yad_proc()
{
kill_proc=$(ps aux | grep "$1" | grep -v "grep $1" | \
awk '{print $2}' | sed 's:^:kill :')
eval $kill_proc
}
function yad_proc_id_string()
{
yad_win_id=`echo $(date +%F-%H-%M-%6N) | \
sed 's/-/_/g' | sed 's/^/text=/'`
yad_win_id_txt_str="--""$yad_win_id"
}
yad_proc_id_string
# ...and here starts my problem...
while [[ $NET_STATE == 0 ]]; do
test_net_connection
if [[ $XCODE == 0 ]]; then
NET_STATE=1
kill_yad_proc "$yad_win_id"
break
exit
else
NET_STATE=0
continue
fi
done | `yad --fixed --skip-taskbar --undecorated \
"$yad_win_id_txt_str" \
--text="Waiting for internet connection..." \
--button='Quit:bash -c "kill -USR1 $YAD_PID"' \
--image=disconnected.png`
In this version script works just partly: when internet is off, yad window appears and disappears when internet is on (ping returns 0). Unfortunately, when I press [Quit] button or [escape] (however I'd like to keep this option), it doesn't work as I'd like it to.
What should I add/change? Where the mistake is done?