Replace $(cat ...) with $(< ...) which help improve the performance.
Signed-off-by: Kairui Song <kasong(a)redhat.com>
---
dracut-module-setup.sh | 6 +++---
kdump-lib.sh | 10 +++++-----
kdumpctl | 6 +++---
mkdumprd | 3 +--
4 files changed, 12 insertions(+), 13 deletions(-)
diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh
index a186570..6a13f53 100755
--- a/dracut-module-setup.sh
+++ b/dracut-module-setup.sh
@@ -94,7 +94,7 @@ kdump_setup_dns() {
_dns=$(echo $_nameserver | cut -d' ' -f2)
[ -z "$_dns" ] && continue
- if [ ! -f $_dnsfile ] || [ ! $(cat $_dnsfile | grep -q $_dns) ]; then
+ if [ ! -f $_dnsfile ] || [ ! $(< $_dnsfile | grep -q $_dns) ]; then
echo "nameserver=$_dns" >> "$_dnsfile"
fi
done < "/etc/resolv.conf"
@@ -239,7 +239,7 @@ kdump_setup_bridge() {
kdump_setup_bond() {
local _netdev=$1
local _dev _mac _slaves _kdumpdev
- for _dev in `cat /sys/class/net/$_netdev/bonding/slaves`; do
+ for _dev in $(< /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
@@ -777,7 +777,7 @@ kdump_configure_fence_kdump () {
# Install a random seed used to feed /dev/urandom
# By the time kdump service starts, /dev/uramdom is already fed by systemd
kdump_install_random_seed() {
- local poolsize=`cat /proc/sys/kernel/random/poolsize`
+ local poolsize=$(< /proc/sys/kernel/random/poolsize)
if [ ! -d ${initdir}/var/lib/ ]; then
mkdir -p ${initdir}/var/lib/
diff --git a/kdump-lib.sh b/kdump-lib.sh
index e18c473..8bb424c 100755
--- a/kdump-lib.sh
+++ b/kdump-lib.sh
@@ -13,7 +13,7 @@ is_fadump_capable()
# Check if firmware-assisted dump is enabled
# if no, fallback to kdump check
if [ -f $FADUMP_ENABLED_SYS_NODE ]; then
- rc=`cat $FADUMP_ENABLED_SYS_NODE`
+ rc=$(< $FADUMP_ENABLED_SYS_NODE)
[ $rc -eq 1 ] && return 0
fi
return 1
@@ -501,7 +501,7 @@ check_crash_mem_reserved()
{
local mem_reserved
- mem_reserved=$(cat /sys/kernel/kexec_crash_size)
+ mem_reserved=$(< /sys/kernel/kexec_crash_size)
if [ $mem_reserved -eq 0 ]; then
echo "No memory reserved for crash kernel"
return 1
@@ -527,7 +527,7 @@ check_current_kdump_status()
return 1
fi
- rc=`cat /sys/kernel/kexec_crash_loaded`
+ rc=$(< /sys/kernel/kexec_crash_loaded)
if [ $rc == 1 ]; then
return 0
else
@@ -682,7 +682,7 @@ prepare_kdump_bootinfo()
boot_imglist="$KDUMP_IMG-$KDUMP_KERNELVER$KDUMP_IMG_EXT $machine_id/$KDUMP_KERNELVER/$KDUMP_IMG"
# Use BOOT_IMAGE as reference if possible, strip the GRUB root device prefix in (hd0,gpt1) format
- local boot_img="$(cat /proc/cmdline | sed "s/^BOOT_IMAGE=\((\S*)\)\?\(\S*\) .*/\2/")"
+ local boot_img="$(< /proc/cmdline | sed "s/^BOOT_IMAGE=\((\S*)\)\?\(\S*\) .*/\2/")"
if [ -n "$boot_img" ]; then
boot_imglist="$boot_img $boot_imglist"
fi
@@ -734,7 +734,7 @@ prepare_cmdline()
local cmdline id
if [ -z "$1" ]; then
- cmdline=$(cat /proc/cmdline)
+ cmdline=$(< /proc/cmdline)
else
cmdline="$1"
fi
diff --git a/kdumpctl b/kdumpctl
index 2248da4..06afc45 100755
--- a/kdumpctl
+++ b/kdumpctl
@@ -200,7 +200,7 @@ restore_default_initrd()
if [ -f $DEFAULT_INITRD_BAK ] && [ -f $INITRD_CHECKSUM_LOCATION ]; then
# verify checksum before restoring
backup_checksum=`sha1sum $DEFAULT_INITRD_BAK | awk '{ print $1 }'`
- default_checksum=`cat $INITRD_CHECKSUM_LOCATION | awk '{ print $1 }'`
+ default_checksum=$(< $INITRD_CHECKSUM_LOCATION | awk '{ print $1 }')
if [ "$default_checksum" != "$backup_checksum" ]; then
echo "WARNING: checksum mismatch! Can't restore original initrd.."
else
@@ -839,7 +839,7 @@ propagate_ssh_key()
show_reserved_mem()
{
- local mem=$(cat /sys/kernel/kexec_crash_size)
+ local mem=$(< /sys/kernel/kexec_crash_size)
local mem_mb=$(expr $mem / 1024 / 1024)
echo "Reserved "$mem_mb"MB memory for crash kernel"
@@ -848,7 +848,7 @@ show_reserved_mem()
check_current_fadump_status()
{
# Check if firmware-assisted dump has been registered.
- rc=`cat $FADUMP_REGISTER_SYS_NODE`
+ rc=$(< $FADUMP_REGISTER_SYS_NODE)
[ $rc -eq 1 ] && return 0
return 1
}
diff --git a/mkdumprd b/mkdumprd
index 36f71b7..c13b746 100644
--- a/mkdumprd
+++ b/mkdumprd
@@ -330,7 +330,6 @@ for_each_block_target()
}
-
#judge if a specific device with $1 is unresettable
#return false if unresettable.
is_unresettable()
@@ -340,7 +339,7 @@ is_unresettable()
if [ -f "$path" ]
then
- resettable="$(cat $path)"
+ resettable="$(< $path)"
[ $resettable -eq 0 -a "$OVERRIDE_RESETTABLE" -eq 0 ] && {
local device=$(udevadm info --query=all --path=/sys/dev/block/$1 | awk -F= '/DEVNAME/{print $2}')
echo "Error: Can not save vmcore because device $device is unresettable"
--
2.26.2