2022-12-01 11:16:46 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
function g_retrycmd {
|
|
|
|
# If retry delay not set default to 5 seconds
|
|
|
|
[ -z "$g_tries_delay" ] && g_tries_delay=5
|
|
|
|
# If retrys not set default to 5 times
|
|
|
|
[ -z "$g_tries" ] && g_tries=5
|
2022-12-01 17:43:31 +01:00
|
|
|
|
2023-01-17 10:24:32 +01:00
|
|
|
#>&2 echo "$(g_date_print) Trying $@"
|
2022-12-06 13:58:54 +01:00
|
|
|
|
2022-12-01 11:16:46 +01:00
|
|
|
local g_try=0
|
|
|
|
until [ $g_try -eq $g_tries ]
|
|
|
|
do
|
|
|
|
((g_try=g_try+1))
|
2023-01-17 10:24:32 +01:00
|
|
|
#>&2 echo "$(g_date_print) Try $g_try of $g_tries"
|
2022-12-01 17:43:31 +01:00
|
|
|
echo "$@" >$g_tmp/g_retrycmd.cmd
|
2023-02-06 14:17:50 +01:00
|
|
|
bash $g_tmp/g_retrycmd.cmd && return 0
|
2022-12-01 11:16:46 +01:00
|
|
|
g_return=$?
|
2023-02-07 09:42:07 +01:00
|
|
|
grep -q "test " $g_tmp/g_retrycmd.cmd && return $g_return
|
2023-01-17 10:24:32 +01:00
|
|
|
if [ $g_try -eq $g_tries ]
|
|
|
|
then
|
|
|
|
[ -z "$g_return" ] || g_echo_error "${FUNCNAME}: $@ failed all $g_tries tries"
|
|
|
|
return $g_return
|
|
|
|
fi
|
2022-12-01 11:16:46 +01:00
|
|
|
sleep $g_tries_delay
|
|
|
|
done
|
2022-12-06 12:41:00 +01:00
|
|
|
|
2023-02-06 14:17:50 +01:00
|
|
|
return ${g_return}
|
2022-12-01 11:16:46 +01:00
|
|
|
}
|