retry commands

This commit is contained in:
olli 2022-12-01 11:16:46 +01:00
parent 96dcd7e684
commit d15795e0ab

View File

@ -0,0 +1,19 @@
#!/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
local g_try=0
until [ $g_try -eq $g_tries ]
do
((g_try=g_try+1))
echo "$(g_date_print) Try $g_try of $g_tries -- $@"
$@ && break
g_return=$?
[ $g_try -eq $g_tries ] && return $g_return
sleep $g_tries_delay
done
}