当前位置:网站首页>Shell script if nested for loop script
Shell script if nested for loop script
2022-07-27 06:17:00 【feike_ three】
Introduce through a script shell script Three considerations for writing
List of articles
The script content
Output the device alarm and clear it
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
Explanation of key points of script
- if Judge
j=`/opt/services/epg/bin/ttx/bin/epg_pdc_run_command "epg node fault-management active-notifications"|grep "remoteNFinstance=fake_smf_nfid"` // After the command output processing, the negative value is given to the variable
if [[ $j ]] //if Judge whether the above command has matching results , If there is a match, the result is ture, Otherwise false
- if Loop nesting Syntax
if [command];then
for:
do
"action command"
done
elif
for:
do
"action command"
done
else
"action command"
fi
- Linux Mixed output of command and character transmission
echo `date`" no connetion alarm" // Command to put `` in
边栏推荐
猜你喜欢

Leetcode one question per day 30. Concatenate substrings of all words

遥感影像识别-训练策略

Leetcode每日一题30. 串联所有单词的子串

UnityShader-高斯模糊

Summary of the use of C # Jason code in TCP communication

Reading and writing of file content - data flow

OSG environment construction (win10+vs2019)

wireshark图形界面抓包

Brief introduction to unity menu interface

5G的前世今生---简述移动通信的发展
随机推荐
Force buckle 110. Balanced binary tree
Dynamic planning for solving problems (5)
ULCL功能--5GC
PZK学C语言之数据类型,进制转换,输入输出,运算符,分支语句ifelse
Remote sensing image recognition misclassification under multi class recognition
SQL初识
Calculation of Huffman tree, code implementation and proof, graphic interpretation
C语言-自定义结构类型
力扣题解 动态规划(6)
SQL novice
UnityShader-LowPoly
ROS运行管理之launch文件
Progress in remote sensing image recognition 2022/5/5
性感素数(Acwing每日一题)
Li Kou 236. the nearest common ancestor of binary tree
软件测试基础概念篇
力扣题解 二叉树(5)
网络原理的简单认识
Unity 实用小技巧(更新ing)
tqdm无法单行显示的问题