栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

shell script if嵌套for循环脚本

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

shell script if嵌套for循环脚本

通过一个脚本介绍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"    //命令要放到``里
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/988360.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号