community-content
community-content copied to clipboard
Failover Script
shellcheck shows improvement potential for this failover script:
In a line 9:
pard=$4
^--^ SC2034: pard appears unused. Verify use (or export if used externally).
In a line 12:
curl=`whereis curl|awk '{ print $2 }'`
^-- SC2006: Use $(...) notation instead of legacy backticked `...`.
Did you mean:
curl=$(whereis curl|awk '{ print $2 }')
In a line 13:
if [ $? -ne 0 ] ; then echo "Curl is not properly configured" ; exit 1 ; fi
^-- SC2181: Check exit code directly with e.g. 'if mycmd;', not indirectly with $?.
In a line 20:
echo $para | grep -E "\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b" > /dev/null 2>&1
^---^ SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
echo "$para" | grep -E "\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b" > /dev/null 2>&1
In a line 23:
if [ $? -eq 0 ]
^-- SC2181: Check exit code directly with e.g. 'if mycmd;', not indirectly with $?.
In a line 36:
if [ -z "$parc" -a "$parb" == "set" ] ; then echo "You have to specify the IP address of the failover server" ; exit 1 ; fi
^-- SC2166: Prefer [ p ] && [ q ] as [ p -a q ] is not well defined.
In a line 40:
read user
^--^ SC2162: read without -r will mangle backslashes.
In a line 42:
read pass
^--^ SC2162: read without -r will mangle backslashes.
In a line 48:
resources=`cat $resourcedir/* | grep "resource" | awk '{ print $2 }'`
^-- SC2006: Use $(...) notation instead of legacy backticked `...`.
Did you mean:
resources=$(cat $resourcedir/* | grep "resource" | awk '{ print $2 }')
In a line 50:
if [ $? -ne 0 ]
^-- SC2181: Check exit code directly with e.g. 'if mycmd;', not indirectly with $?.
In a line 57:
if [ -z $para ]
^---^ SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
if [ -z "$para" ]
In a line 61:
echo $resources
^--------^ SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
echo "$resources"
In a line 65:
echo $resources | grep $para > /dev/null
^--------^ SC2086: Double quote to prevent globbing and word splitting.
^---^ SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
echo "$resources" | grep "$para" > /dev/null
In a line 67:
if [ $? -ne 0 ]
^-- SC2181: Check exit code directly with e.g. 'if mycmd;', not indirectly with $?.
In a line 71:
echo $resources
^--------^ SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
echo "$resources"
In a line 75:
ip=`cat $resourcedir/$para | grep "^ip" | awk '{ print $2 }'`
^-- SC2006: Use $(...) notation instead of legacy backticked `...`.
^----------------^ SC2002: Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.
^---^ SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
ip=$(cat $resourcedir/"$para" | grep "^ip" | awk '{ print $2 }')
In a line 77:
user=`cat $resourcedir/$para | grep "user" | awk '{ print $2 }'`
^-- SC2006: Use $(...) notation instead of legacy backticked `...`.
^----------------^ SC2002: Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.
^---^ SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
user=$(cat $resourcedir/"$para" | grep "user" | awk '{ print $2 }')
In a line 78:
pass=`cat $resourcedir/$para | grep "password" | awk '{ print $2 }'`
^-- SC2006: Use $(...) notation instead of legacy backticked `...`.
^----------------^ SC2002: Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.
^---^ SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
pass=$(cat $resourcedir/"$para" | grep "password" | awk '{ print $2 }')
In a line 87:
get=`$curl -s -u $user:$pass $uri/$ip`
^-- SC2006: Use $(...) notation instead of legacy backticked `...`.
^---^ SC2086: Double quote to prevent globbing and word splitting.
^---^ SC2086: Double quote to prevent globbing and word splitting.
^-^ SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
get=$($curl -s -u "$user":"$pass" $uri/"$ip")
In a line 91:
echo $get
^--^ SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
echo "$get"
In a line 101:
echo $get
^--^ SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
echo "$get"
In a line 105:
yamlip=`echo "$get" | grep "^ ip" | awk '{ print $2 }'`
^-- SC2006: Use $(...) notation instead of legacy backticked `...`.
Did you mean:
yamlip=$(echo "$get" | grep "^ ip" | awk '{ print $2 }')
In a line 106:
yamlserverip=`echo "$get" | grep "^ server_ip" | awk '{ print $2 }'`
^-- SC2006: Use $(...) notation instead of legacy backticked `...`.
Did you mean:
yamlserverip=$(echo "$get" | grep "^ server_ip" | awk '{ print $2 }')
In a line 107:
yamlactiveip=`echo "$get" | grep "^ active_server_ip" | awk '{print $2 }'`
^-- SC2006: Use $(...) notation instead of legacy backticked `...`.
Did you mean:
yamlactiveip=$(echo "$get" | grep "^ active_server_ip" | awk '{print $2 }')
In a line 114:
then echo "the configured failover server(s) is/are: `cat $resourcedir/$para | grep "^failover_ip" | sed -e 's/failover_ip //g'`" ; fi
^-- SC2006: Use $(...) notation instead of legacy backticked `...`.
^----------------^ SC2002: Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.
^---^ SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
then echo "the configured failover server(s) is/are: $(cat $resourcedir/"$para" | grep "^failover_ip" | sed -e 's/failover_ip //g')" ; fi
In a line 119:
if [ -z $parc ]
^---^ SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
if [ -z "$parc" ]
In a line 122:
echo "the configured failover server(s) is/are: `cat $resourcedir/$para | grep "^failover_ip" | sed -e 's/failover_ip //g'`"
^-- SC2006: Use $(...) notation instead of legacy backticked `...`.
^----------------^ SC2002: Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.
^---^ SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
echo "the configured failover server(s) is/are: $(cat $resourcedir/"$para" | grep "^failover_ip" | sed -e 's/failover_ip //g')"
In a line 127:
set=`$curl -s -u $user:$pass $uri/$ip -d active_server_ip=$parc`
^-- SC2006: Use $(...) notation instead of legacy backticked `...`.
^---^ SC2086: Double quote to prevent globbing and word splitting.
^---^ SC2086: Double quote to prevent globbing and word splitting.
^-^ SC2086: Double quote to prevent globbing and word splitting.
^---^ SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
set=$($curl -s -u "$user":"$pass" $uri/"$ip" -d active_server_ip="$parc")
In a line 151:
yamlip=`echo "$set" | grep "^ ip" | awk '{ print $2 }'`
^-- SC2006: Use $(...) notation instead of legacy backticked `...`.
Did you mean:
yamlip=$(echo "$set" | grep "^ ip" | awk '{ print $2 }')
In a line 152:
yamlserverip=`echo "$set" | grep "^ server_ip" | awk '{ print $2 }'`
^-- SC2006: Use $(...) notation instead of legacy backticked `...`.
Did you mean:
yamlserverip=$(echo "$set" | grep "^ server_ip" | awk '{ print $2 }')
In a line 153:
yamlactiveip=`echo "$set" | grep "^ active_server_ip" | awk '{ print $2 }'`
^-- SC2006: Use $(...) notation instead of legacy backticked `...`.
Did you mean:
yamlactiveip=$(echo "$set" | grep "^ active_server_ip" | awk '{ print $2 }')
In a line 160:
then echo "the configured failover server(s) is/are: `cat $resourcedir/$para | grep "^failover_ip" | sed -e 's/failover_ip //g'`" ; fi
^-- SC2006: Use $(...) notation instead of legacy backticked `...`.
^----------------^ SC2002: Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.
^---^ SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
then echo "the configured failover server(s) is/are: $(cat $resourcedir/"$para" | grep "^failover_ip" | sed -e 's/failover_ip //g')" ; fi
In a line 167:
script=`grep "script" $resourcedir/$para | awk '{ print $2 }'`
^-- SC2006: Use $(...) notation instead of legacy backticked `...`.
^---^ SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
script=$(grep "script" $resourcedir/"$para" | awk '{ print $2 }')
In a line 174:
elif [ -x $script ]
^-----^ SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
elif [ -x "$script" ]
In a line 176:
./$0 $para set $parc
^-- SC2086: Double quote to prevent globbing and word splitting.
^---^ SC2086: Double quote to prevent globbing and word splitting.
^---^ SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
./"$0" "$para" set "$parc"
In a line 177:
if [ $? = 0 ] ; then $script ; else exit 1 ; fi
^-- SC2181: Check exit code directly with e.g. 'if mycmd;', not indirectly with $?.
In a line 178:
elif [ -f $script ]
^-----^ SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
elif [ -f "$script" ]
In a line 185:
if [ -n $parb ]
^---^ SC2070: -n doesn't work with unquoted arguments. Quote or use [[ ]].
^---^ SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
if [ -n "$parb" ]
For more information:
https://www.shellcheck.net/wiki/SC2070 -- -n doesn't work with unquoted arg...
https://www.shellcheck.net/wiki/SC2034 -- pard appears unused. Verify use (...
https://www.shellcheck.net/wiki/SC2166 -- Prefer [ p ] && [ q ] as [ p -a q...
I could fix this, but where can I upload a fixed version, @Flipez , @LKaemmerling , @fdrechsler ?
Hi @thomasmerz, you can open a PR for the files.
I will make sure it also gets forwarded to the initial author, thanks for pointing out @53c70r !
Ok, let's see if I'll get this done this weekend.
BTW: I do not do it because of https://github.com/hetzneronline/community-content/issues/432 , so please don't get me wrong, but I just wanted to ask/remind if this would be "rewardable" for a small long-time-customer? 😉
@Flipez Wow, that seemed much easier than I feared and than many other scripts I shellcheck
'ed before… 😄
Due to not having/using a failover IP I'm not able to check and garantee that the shellcheck
'ed version works as good as it did before 🤷🏻♂️
@Flipez , please review my PR #455 - thank you.
@thomasmerz Sorry that we did not review your PR yet. We are a bit busy on our end. I forwarded the PR to the relevant people as I can not review this one. Someone should take care of it soonish.
@Flipez , I'm still waiting for a review… 🤔