概述
通过一个脚本介绍shell script编写的三个注意事项
文章目录
- 脚本内容
- 脚本关键点讲解
脚本内容
输出设备告警并将其清除
bash-4.3$ cat clear_alarm.sh
#!/bin/bash
j=`/opt/services/epg/bin/ttx/bin/epg_pdc_run_command "epg node fault-management active-notifications"|grep "remoteNFinstance=fake_smf_nfid"`
i=`/opt/services/epg/bin/ttx/bin/epg_pdc_run_command "epg node fault-management active-notifications"|grep "remoteNFinstance=ismf-notify"`
if [[ $j ]];then
for k in `/opt/services/epg/bin/ttx/bin/epg_pdc_run_command "epg node fault-management active-notifications"| grep -B5 "remoteNFinstance=fake_smf_nfid" | grep fault-id | awk -F " " '{print $2}'`:
do
/opt/services/epg/bin/ttx/bin/epg_pdc_run_command "epg node fault-management active-notifications" >>alarm.log
/opt/services/epg/bin/ttx/bin/epg_pdc_run_command "epg node fault-management clear-notification fault-id $k" >>alarm.log
done
elif [[ $i ]];then
for g in `/opt/services/epg/bin/ttx/bin/epg_pdc_run_command "epg node fault-management active-notifications"| grep -B5 "remoteNFinstance=ismf-notify" | grep fault-id | awk -F " " '{print $2}'`:
do
/opt/services/epg/bin/ttx/bin/epg_pdc_run_command "epg node fault-management active-notifications" >>alarm.log
/opt/services/epg/bin/ttx/bin/epg_pdc_run_command "epg node fault-management clear-notification fault-id $g" >>alarm.log
done
else
echo `date`" no connetion alarm" >>alarm.txt
fi
脚本关键点讲解
- if判断
j=`/opt/services/epg/bin/ttx/bin/epg_pdc_run_command "epg node fault-management active-notifications"|grep "remoteNFinstance=fake_smf_nfid"` //命令输出处理后负值给变量
if [[ $j ]] //if判断上面命令是否有匹配结果,如果有匹配结果为ture,否则为false
- if循环嵌套语法
if [command];then
for:
do
"action command"
done
elif
for:
do
"action command"
done
else
"action command"
fi
- Linux命令和字符传混合输出
echo `date`" no connetion alarm" //命令要放到``里
最后
以上就是火星上心情为你收集整理的shell script if嵌套for循环脚本脚本内容脚本关键点讲解的全部内容,希望文章能够帮你解决shell script if嵌套for循环脚本脚本内容脚本关键点讲解所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复