温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

shell 脚本应用《八》多个脚本命令例子

发布时间:2020-06-29 15:04:38 来源:网络 阅读:141 作者:wx5cb5dcd871bbc 栏目:系统运维

写一个脚本,实现判断192.168.0.0/24网络里,当前在线用户的IP有哪些
命令:

nmap -sP 192.168.0.0/24
脚本1

#!/bin/bash

for I in seq 1 255
do
ping -c 2 -W 2 192.168.0.$I &>/dev/null
if [ $? -eq 0 ]
then
echo -e "192.168.0.$I is up."
else
echo -e "192.168.0.$I is down."
fi
done

单词及字母去重排序案例

[root@localhost scripts]# sed 's#[,.]##g' <test.log|tr " " "\n"|sort|uniq -c |sort -rn|head -5
4 the
3 to
2 was
2 months
2 I
[root@localhost scripts]#

[root@localhost scripts]# tr " ," "\n" <test.log|awk '{S[$1]++}END{for(k in S) print S[k],k}'|sort -rn|head -5
4 the
3 to
2 was
2 months
2 I
[root@localhost scripts]#

[root@localhost scripts]# awk -F "[ ,.]+" '{for(i=1;i<NF;i++)S[$i]++}END{for(k in S) print S[k],k}' test.log |sort -rn|head -5
4 the
3 to
2 was
2 months
2 I
[root@localhost scripts]#

[root@localhost scripts]# sed 's#[,. ]##g' test.log|grep -o "."|sort|uniq -c|sort -rn|head -5
33 t
20 o
19 e
18 n
17 i
[root@localhost scripts]#

按字母出现频率降序排序

方法1:去空格特殊字符后,然后利用grep的-o将字符竖向排列后处理。
[root@localhost scripts]# sed 's#[,. ]##g' test.log|grep -o "."|sort|uniq -c|sort -rn|head -5
33 t
20 o
19 e
18 n
17 i
[root@localhost scripts]#

[root@localhost scripts]# sed 's#[,. ]##g' test.log|grep -o "."|awk '{S[$1]++}END{for(k in S) print S[k],k}'|sort -rn|head -5
33 t
20 o
19 e
18 n
17 i
[root@localhost scripts]#

[root@localhost scripts]# sed 's#[,. ]##g' test.log|awk -F "" '{for(i=1;i<NF;i++)S[$i]++}END{for(k in S) print S[k],k}'|sort -rn|head -5
33 t
20 o
18 n
18 e
17 i
[root@localhost scripts]#

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI