Re:An almost perfect rsync over SSH backup script
by chasil on Friday February 25, 2022 @11:55AM
(#30469320)
If I may add a few critiques...
# Make sure no one else is using rsync
pro_on=$(ps aux | grep -c rsync)
A better way to do that is with the flock utility.
(
flock -n 9 || exit 1 # Critical section-allow only one process.
...single thread shell script
) 9> ~/.empty_lock_file
Note that the flock utility is specific to Linux, but POSIX mkdir() is atomic and could be more portable.
"${SOURCES[@]}"
POSIX shells do not support arrays. Iterating with read over a here document is more portable.
minutes=$(($minutes - 1))
POSIX is specific that the $ prefix on a variable name can be omitted in an arithmetic expression.
ECHO="/bin/echo"
Many shell scripts never use echo, and this is a good idea. 'NEVER use echo like this. According to POSIX, echo has unspecified behavior if any of its arguments contain "\" or if its first argument is "-n".' http://www.etalabs.net/sh_tricks.html
Perhaps use this instead, in a subshell to avoid stomping on variables:
myecho () ( z=''; for x; do printf "$z%s" "$x"; z=' '; done; )
Perhaps use this instead, in a subshell to avoid stomping on variables: