- 论坛徽章:
- 18
|
觉得利用临时文件来保存中间结果的方法太耗费资源,又改了一下脚本,利用变量来保存中间结果。- show_port(){
- result1=$(grep 127 ~/.bash_profile |awk -F'[= ]' '/-p [0-9]+.*/{printf("%-20s\t%d\n",$2,$(NF-2))}')
- result2=$(find /home/enb -type f -name 'z.port*'|xargs egrep -H '[0-9]+'|awk -F. 'split($NF,a,":"){printf("%-20s\t%d\n",a[1],a[2])}')
- alive=$(netstat -ta|awk -F"[ :]+" '/localhost:/{print$5}')
- final=$(echo -e "$result1\n$result2"|awk -va="$alive" -vOFS='\t' '{print $0,(a~$2)?"on":"off"}')
- printf %-20s"\t"%s"\t"%s"\n" Host Port Status
- echo "--------------------------------------"
- echo "$final"|grep on|sort -nk2
- echo "--------------------------------------"
- echo "$final"|grep off|sort -nk2
- }
复制代码 |
|