bash脚本
for i in $script_name
do
echo -en "running the script - $i\t - "
exec 3>&1 4>&2
var=$( { time /tmp/scripts/$i 1>&3 2>&4; } 2>&1) # Captures time only
exec 3>&- 4>&-
echo "$var"
done
打印以下内容:
running the script - Verify_disk.bash - 1.42
running the script - Verify_yum_list.bash - 10.49
running the script - Verify_size.bash - 2.93
running the script - Verify_mem_size.bash - 0.71
running the script - Verify_disk_size.bash - 2.41
running the script - Verify_wdisk.bash - 1.63
running the script - Verify_cpu.bash - 0.74
因为$ var是打印所有这些输出的变量,所以我们要对齐输出
所以会是这样
running the script - Verify_disk.bash - 1.42
running the script - Verify_yum_list.bash - 10.49
running the script - Verify_size.bash - 2.93
running the script - Verify_mem_size.bash - 0.71
running the script - Verify_disk_size.bash - 2.41
running the script - Verify_wdisk.bash - 1.63
running the script - Verify_cpu.bash - 0.74
为了对齐最后一个字段,$ var应该进行哪些其他更改?
进行预循环以计算最长的文件名,然后将其用作间距参数:
longest=0
for file in *.bash
do
[ "${#file}" -gt "$longest" ] && longest=${#file}
done
# ... for your execution loop
printf "running the script - %${longest}s\t- "
printf "%s\n" "$var"
我认为通配符涵盖了您的所有脚本*.bash
;根据需要进行调整。初始循环计算所需的宽度;最初printf
使用该变量为for
循环的每次迭代设置脚本字段的宽度格式。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句