通过一个脚本介绍shell script编写的三个注意事项
文章目录
- 脚本内容
- 脚本关键点讲解
脚本内容
输出设备告警并将其清除
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20bash-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
3j=`/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
15if [command];then for: do "action command" done elif for: do "action command" done else "action command" fi
- Linux命令和字符传混合输出
复制代码
1
2echo `date`" no connetion alarm" //命令要放到``里
最后
以上就是火星上心情最近收集整理的关于shell script if嵌套for循环脚本脚本内容脚本关键点讲解的全部内容,更多相关shell内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复