retry commands
This commit is contained in:
parent
96dcd7e684
commit
d15795e0ab
19
gaboshlib/g_retrycmd.bashfunc
Normal file
19
gaboshlib/g_retrycmd.bashfunc
Normal 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
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user