shell study-12day--shell实例
2020-12-27 22:20
1961 查看
1、shell实例
(1)打印九九乘法表
[root@test shell]# vi for-1.sh #!/bin/bash for i in `seq 9` #变量i取1-9之间的整数 do for j in `seq $i` #变量j分别取1-1,1-2,1-3...1-9之间的整数 do echo -n "$i*$j= `echo $(($i*$j))` " #不换行输出变量i与变量j相乘的结果 done echo " " done
(2)ping整个网段地址,并输出结果到指定文件
[root@test shell]# vi ping.sh #!/bin/bash for i in `seq 254` do ping -c 3 192.168.0.$i &>/dev/null if [ $? = 0 ]; then echo "192.168.0.$i up ">>ping.txt else echo "192.168.0.$i down" >> ping.txt fi done
(3)抓取指定网口实时流量
[root@test shell]# vi liuliang.sh #!/bin/bash ethn=$1 while true #每执行一次while true,就会调用true命令。 #true用于和其他命令进行逻辑运算。返回状态总是成功;返回值为0。 do RX_pre=$(cat /proc/net/dev | grep $ethn | sed 's/:/ /g' | awk '{print $2}') TX_pre=$(cat /proc/net/dev | grep $ethn | sed 's/:/ /g' | awk '{print $10}') sleep 1 RX_next=$(cat /proc/net/dev | grep $ethn | sed 's/:/ /g' | awk '{print $2}') TX_next=$(cat /proc/net/dev | grep $ethn | sed 's/:/ /g' | awk '{print $10}') clear echo -e "\t RX `date +%k:%M:%S` TX" RX=$((${RX_next}-${RX_pre})) TX=$((${TX_next}-${TX_pre})) if [[ $RX -lt 1024 ]];then RX="${RX}B/s" elif [[ $RX -gt 1048576 ]];then RX=$(echo $RX | awk '{print $1/1048576 "MB/s"}') else RX=$(echo $RX | awk '{print $1/1024 "KB/s"}') fi if [[ $TX -lt 1024 ]];then TX="${TX}B/s" elif [[ $TX -gt 1048576 ]];then TX=$(echo $TX | awk '{print $1/1048576 "MB/s"}') else TX=$(echo $TX | awk '{print $1/1024 "KB/s"}') fi echo -e "$ethn \t $RX $TX " done [root@test shell]# sh liuliang.sh eth0
个人公众号:
相关文章推荐
- shell脚本和awk实践
- shell study-9day--shell流程控制语句case
- shell脚本中如何给一段文字加颜色
- (十五)、shell脚本之简单控制流结构
- shell脚本之 函数
- 使用shell发送邮件,方便快捷
- shell study-3day--shell变量及实例
- 骑士CMSgetshell复现
- 创建你的第一个shell脚本
- 横向无文件移动--SCshell使用
- 编写shell脚本自动安装node.js环境
- WQL——用于PowerShell中获取WMI对象的查询语言
- 禅道12.4.2后台管理员权限Getshell
- 利用官网getshell
- SHELL 脚本编程基础
- shell脚本实现磁盘监控系统
- 一键配置本地yum源的shell脚本
- Shell文本处理三剑客之sed的使用
- Shell用sed命令删除特定行的方法
- 详解NC反弹shell的几种方法