通过一个脚本介绍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 ]];thenfor 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.logdone
elif [[ $i ]];thenfor 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.logdone
elseecho `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];thenfor:do"action command"done
eliffor:do"action command"      done
else"action command"
fi
  • Linux命令和字符传混合输出
echo `date`" no connetion alarm"    //命令要放到``里

shell script if嵌套for循环脚本相关推荐

  1. Shell 编程 Shell Script

    Shell Script简介 什么是shell script? shell:与内核通信的工具: script:脚本: shell script:针对shell所写的脚本. 利用shell功能所写的一个 ...

  2. 那些年我们一起追过的Shell Script

    原本这是自己在几个月前为公司的一个分享活动写的一个投影片,今天趁大脑负荷比较小,把这个话题拿到blog上面来分享一下.从知道shell算起至今也就几个年头而已,如今勉强算是入门了.对某一个新事物的掌握 ...

  3. 【shell脚本开发技术】linux中shell script脚本开发编程常用命令与脚本速记指南

    shell script #!/bin/bash # do something run shell script sh script.shorchmod a+x script.sh ./script. ...

  4. Shell 和 Shell 脚本 (Shell Script)

    Shell 是一个用 C 语言编写的程序,这个应用程序提供了一个界面,用户通过这个界面访问操作系统内核的服务. 业界所说的 Shell 通常都是指 Shell 脚本,但要知道,Shell 和 Shel ...

  5. mac上编写运行shell script(shell脚本)

    shell的历史 Shell 是一个用 C 语言编写的程序,它是用户使用 Linux 的桥梁.Shell 既是一种命令语言,又是一种程序设计语言. Shell 是指一种应用程序,这个应用程序提供了一个 ...

  6. Linux shell script 的语法汇总

    2019独角兽企业重金招聘Python工程师标准>>> 条件判断式 if判断式 if [ 条件判断式1 ]:then执行动作 elif [ 条件判断式2 ]:then执行动作 els ...

  7. linux-basic(13)学习shell script

    [13.1]什么是shell script? 1)shell script 是利用 shell 的功能所写的一个『程序 (program)』,这个程序是使用纯文字档,将一些 shell 的语法与命令( ...

  8. 从零开始学习大数据系列之Linux-02Vim与Shell script

    从零开始学习大数据系列之Linux-02Vim与Shell script Shell Shell概述 Shell是允许用户输入命令的界面,即命令解释器.用于接收应用程序/用户的命令,然后调用操作系统内 ...

  9. 20单元——学习正解表达式及学习实践 Shell script

    正则表达式: 处理字符串的表示方式,它以行为单位来进行字符串的处理操作,正则表达式通过一些特殊符号的辅助,可以让用户轻易地完成[查找.删除.替换]某特定字符串的处理过程. 正则表达式的字符串表达方式依 ...

最新文章

  1. mysql 事务 锁 并发
  2. yii2 mysql_Yii2 数据库操作汇总
  3. android java 8_四个库,让你在 Android 中启用 Java 8 功能
  4. logback日志配置
  5. 技能的反面 - 魔方和模仿
  6. 入选 SIGMOD2021 的时间序列多周期检测通用框架 RobustPeriod 如何支撑阿里业务场景?
  7. Adobe illustrator 魔棒工具批量操作 - 连载 7
  8. linuxC编程实战 my_server.c例子问题总结
  9. vue组件化开发学习笔记-3-组件插槽
  10. 数据结构C语言版 学习整理
  11. QT QML 3D模型查看器
  12. UTF-8、BOM、feff的问题
  13. 神经网络模型的实际案例,神经网络模型应用实例
  14. 博通无线网卡驱动安装linux,Ubuntu下Broadcom 802.11g无线网卡驱动安装方法
  15. PySpark机器学习 ML
  16. java 泰国_游记:泰国之旅
  17. 利用Visual C++ 实现QQ消息群发 ,大神实际测试,已成功发送消息
  18. html中名词解释,HTML相关名词解释
  19. 基于web在线购物商城网站的设计与实现(学生网页设计作业源码)
  20. 数位dp【模板 + 老年康复】

热门文章

  1. wifi开启位置服务器,如何设置wifi定位服务器地址
  2. 我用python代码表白,泡到了大学小师妹
  3. win10系统截图快捷键
  4. 魔术师usm安装服务器系统,魔术师u盘一键装系统
  5. 关于log4j:WARN No appenders could be found for logger (org.apache.hadoop.metrics2.lib.MutableMetricsFa
  6. PyBullet快速上手教程
  7. 浅识Flutter 基本组件之showDatePicker方法
  8. ASP计算周开始和一年有多少周及某年第一周开始日期
  9. mac升级mysql_Mac如何升级Mysql数据库 Mac升级Mysql数据库步骤
  10. torch cosine_similarity 批量两两计算cos值