我是靠谱客的博主 火星上心情,这篇文章主要介绍shell script if嵌套for循环脚本脚本内容脚本关键点讲解,现在分享给大家,希望可以做个参考。

通过一个脚本介绍shell script编写的三个注意事项

文章目录

  • 脚本内容
  • 脚本关键点讲解

脚本内容

输出设备告警并将其清除

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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判断
复制代码
1
2
3
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循环嵌套语法
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
if [command];then for: do "action command" done elif for: do "action command" done else "action command" fi
  • Linux命令和字符传混合输出
复制代码
1
2
echo `date`" no connetion alarm" //命令要放到``里

最后

以上就是火星上心情最近收集整理的关于shell script if嵌套for循环脚本脚本内容脚本关键点讲解的全部内容,更多相关shell内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(71)

评论列表共有 0 条评论

立即
投稿
返回
顶部