bash scripts: use $(...) notation instead of legacy ...

This is a batch update done with following command:

`sed -i -e 's/`\([^`]*\)`/\$(\1)/g' mkfadumprd mkdumprd \
 kdumpctl dracut-module-setup.sh dracut-fadump-module-setup.sh \
 dracut-early-kdump-module-setup.sh`

And manually converted some corner cases. This fixes
all related issues detected by shellcheck.
Make it easier to do clean up in later commits.

Check following link for reasons to switch to the new syntax:
https://github.com/koalaman/shellcheck/wiki/SC2006

Signed-off-by: Kairui Song <kasong@redhat.com>
Acked-by: Philipp Rudo <prudo@redhat.com>
This commit is contained in:
Kairui Song 2021-09-08 01:48:52 +08:00
parent a416930706
commit 54cc5c44be
2 changed files with 26 additions and 27 deletions

View File

@ -266,8 +266,8 @@ kdump_static_ip() {
/sbin/ip $_ipv6_flag route show | grep -v default |\
grep ".*via.* $_netdev " | grep -v "^[[:space:]]*nexthop" |\
while read -r _route; do
_target=`echo $_route | cut -d ' ' -f1`
_nexthop=`echo $_route | cut -d ' ' -f3`
_target=$(echo $_route | cut -d ' ' -f1)
_nexthop=$(echo $_route | cut -d ' ' -f3)
if [ "x" != "x"$_ipv6_flag ]; then
_target="[$_target]"
_nexthop="[$_nexthop]"
@ -293,9 +293,9 @@ kdump_handle_mulitpath_route() {
[[ "$_target" == 'default' ]] && continue
[[ "$_route" =~ .*via.*\ $_netdev ]] || continue
_weight=`echo "$_route" | cut -d ' ' -f7`
_weight=$(echo "$_route" | cut -d ' ' -f7)
if [[ "$_weight" -gt "$_max_weight" ]]; then
_nexthop=`echo "$_route" | cut -d ' ' -f3`
_nexthop=$(echo "$_route" | cut -d ' ' -f3)
_max_weight=$_weight
if [ "x" != "x"$_ipv6_flag ]; then
_rule="rd.route=[$_target]:[$_nexthop]:$kdumpnic"
@ -305,7 +305,7 @@ kdump_handle_mulitpath_route() {
fi
else
[[ -n "$_rule" ]] && echo "$_rule"
_target=`echo "$_route" | cut -d ' ' -f1`
_target=$(echo "$_route" | cut -d ' ' -f1)
_rule="" _max_weight=0 _weight=0
fi
done >> ${initdir}/etc/cmdline.d/45route-static.conf\
@ -383,7 +383,7 @@ kdump_setup_bond() {
local _netdev="$1"
local _nm_show_cmd="$2"
local _dev _mac _slaves _kdumpdev _bondoptions
for _dev in `cat /sys/class/net/$_netdev/bonding/slaves`; do
for _dev in $(cat /sys/class/net/$_netdev/bonding/slaves); do
_mac=$(kdump_get_perm_addr $_dev)
_kdumpdev=$(kdump_setup_ifname $_dev)
echo -n " ifname=$_kdumpdev:$_mac" >> ${initdir}/etc/cmdline.d/42bond.conf
@ -410,7 +410,7 @@ kdump_setup_bond() {
kdump_setup_team() {
local _netdev=$1
local _dev _mac _slaves _kdumpdev
for _dev in `teamnl $_netdev ports | awk -F':' '{print $2}'`; do
for _dev in $(teamnl $_netdev ports | awk -F':' '{print $2}'); do
_mac=$(kdump_get_perm_addr $_dev)
_kdumpdev=$(kdump_setup_ifname $_dev)
echo -n " ifname=$_kdumpdev:$_mac" >> ${initdir}/etc/cmdline.d/44team.conf
@ -532,11 +532,11 @@ kdump_get_remote_ip()
{
local _remote=$(get_remote_host $1) _remote_temp
if is_hostname $_remote; then
_remote_temp=`getent ahosts $_remote | grep -v : | head -n 1`
_remote_temp=$(getent ahosts $_remote | grep -v : | head -n 1)
if [ -z "$_remote_temp" ]; then
_remote_temp=`getent ahosts $_remote | head -n 1`
_remote_temp=$(getent ahosts $_remote | head -n 1)
fi
_remote=`echo $_remote_temp | cut -d' ' -f1`
_remote=$(echo $_remote_temp | cut -d' ' -f1)
fi
echo $_remote
}
@ -908,7 +908,7 @@ get_pcs_fence_kdump_nodes() {
pcs cluster sync > /dev/null 2>&1 && pcs cluster cib-upgrade > /dev/null 2>&1
# get cluster nodes from cluster cib, get interface and ip address
nodelist=`pcs cluster cib | xmllint --xpath "/cib/status/node_state/@uname" -`
nodelist=$(pcs cluster cib | xmllint --xpath "/cib/status/node_state/@uname" -)
# nodelist is formed as 'uname="node1" uname="node2" ... uname="nodeX"'
# we need to convert each to node1, node2 ... nodeX in each iteration

View File

@ -76,7 +76,7 @@ determine_dump_mode()
save_core()
{
coredir="/var/crash/`date +"%Y-%m-%d-%H:%M"`"
coredir="/var/crash/$(date +"%Y-%m-%d-%H:%M")"
mkdir -p $coredir
ddebug "cp --sparse=always /proc/vmcore $coredir/vmcore-incomplete"
@ -290,15 +290,14 @@ get_pcs_cluster_modified_files()
is_generic_fence_kdump && return 1
is_pcs_fence_kdump || return 1
time_stamp=`pcs cluster cib | xmllint --xpath 'string(/cib/@cib-last-written)' - | \
xargs -0 date +%s --date`
time_stamp=$(pcs cluster cib | xmllint --xpath 'string(/cib/@cib-last-written)' - | xargs -0 date +%s --date)
if [ -n $time_stamp -a $time_stamp -gt $image_time ]; then
modified_files="cluster-cib"
fi
if [ -f $FENCE_KDUMP_CONFIG_FILE ]; then
time_stamp=`stat -c "%Y" $FENCE_KDUMP_CONFIG_FILE`
time_stamp=$(stat -c "%Y" $FENCE_KDUMP_CONFIG_FILE)
if [ "$time_stamp" -gt "$image_time" ]; then
modified_files="$modified_files $FENCE_KDUMP_CONFIG_FILE"
fi
@ -358,7 +357,7 @@ check_files_modified()
fi
HOOKS="$HOOKS $POST_FILES $PRE_FILES"
CORE_COLLECTOR=$(kdump_get_conf_val core_collector | awk '{print $1}')
CORE_COLLECTOR=`type -P $CORE_COLLECTOR`
CORE_COLLECTOR=$(type -P $CORE_COLLECTOR)
# POST_FILES and PRE_FILES are already checked against executable, need not to check again.
EXTRA_BINS="$EXTRA_BINS $CHECK_FILES"
CHECK_FILES=$(kdump_get_conf_val extra_bins)
@ -395,13 +394,13 @@ check_files_modified()
for file in $files; do
if [ -e "$file" ]; then
time_stamp=`stat -c "%Y" $file`
time_stamp=$(stat -c "%Y" $file)
if [ "$time_stamp" -gt "$image_time" ]; then
modified_files="$modified_files $file"
fi
if [ -L "$file" ]; then
file=$(readlink -m $file)
time_stamp=`stat -c "%Y" $file`
time_stamp=$(stat -c "%Y" $file)
if [ "$time_stamp" -gt "$image_time" ]; then
modified_files="$modified_files $file"
fi
@ -591,7 +590,7 @@ check_rebuild()
#check to see if dependent files has been modified
#since last build of the image file
if [ -f $TARGET_INITRD ]; then
image_time=`stat -c "%Y" $TARGET_INITRD 2>/dev/null`
image_time=$(stat -c "%Y" $TARGET_INITRD 2>/dev/null)
#in case of fadump mode, check whether the default/target
#initrd is already built with dump capture capability
@ -727,7 +726,7 @@ check_ssh_config()
done <<< "$(kdump_read_conf)"
#make sure they've configured kdump.conf for ssh dumps
local SSH_TARGET=`echo -n $DUMP_TARGET | sed -n '/.*@/p'`
local SSH_TARGET=$(echo -n $DUMP_TARGET | sed -n '/.*@/p')
if [ -z "$SSH_TARGET" ]; then
return 1
fi
@ -814,8 +813,8 @@ propagate_ssh_key()
fi
#now find the target ssh user and server to contact.
SSH_USER=`echo $DUMP_TARGET | cut -d\ -f2 | cut -d@ -f1`
SSH_SERVER=`echo $DUMP_TARGET | sed -e's/\(.*@\)\(.*$\)/\2/'`
SSH_USER=$(echo $DUMP_TARGET | cut -d\ -f2 | cut -d@ -f1)
SSH_SERVER=$(echo $DUMP_TARGET | sed -e's/\(.*@\)\(.*$\)/\2/')
#now send the found key to the found server
ssh-copy-id -i $KEYFILE $SSH_USER@$SSH_SERVER
@ -844,7 +843,7 @@ check_current_fadump_status()
{
# Check if firmware-assisted dump has been registered.
rc=$(<$FADUMP_REGISTER_SYS_NODE)
[[ $rc -eq 1 ]] && return 0
[ $rc -eq 1 ] && return 0
return 1
}
@ -877,9 +876,9 @@ save_raw()
fi
kdump_dir=$(kdump_get_conf_val path)
if [ -z "${kdump_dir}" ]; then
coredir="/var/crash/`date +"%Y-%m-%d-%H:%M"`"
coredir="/var/crash/$(date +"%Y-%m-%d-%H:%M")"
else
coredir="${kdump_dir}/`date +"%Y-%m-%d-%H:%M"`"
coredir="${kdump_dir}/$(date +"%Y-%m-%d-%H:%M")"
fi
mkdir -p "$coredir"
@ -956,8 +955,8 @@ selinux_relabel()
check_fence_kdump_config()
{
local hostname=`hostname`
local ipaddrs=`hostname -I`
local hostname=$(hostname)
local ipaddrs=$(hostname -I)
local nodes=$(kdump_get_conf_val "fence_kdump_nodes")
for node in $nodes; do