加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

shell编程实战7

发布时间:2020-12-16 01:42:09 所属栏目:安全 来源:网络整理
导读:1.?计算文档中数字的个数 ? ? 2.?对比两台机器文件的差异 #!/bin/bash dir=/data/web [ -f /tmp/md5.list ] /tmp/md5.list # /tmp目录是一定存在的,md5.list文件必须清空或删除 find $dir/ -type f /tmp/file.list while read line do md5sum $line /tmp/md

1.?计算文档中数字的个数

? ?

2.?对比两台机器文件的差异

#!/bin/bash

dir=/data/web

[ -f /tmp/md5.list ] && >/tmp/md5.list # /tmp目录是一定存在的,md5.list文件必须清空或删除

find $dir/ -type f > /tmp/file.list
while read line
do
md5sum $line >> /tmp/md5.list # 循环追加
done </tmp/file.list

scp /tmp/md5.list B:/tmp/
[ -f /tmp/check_md5.sh ] && rm -f /tmp/check_md5.sh

# 要嵌入的脚本文件
cat > /tmp/check_md5.sh << EOF
#!/bin/bash
dir=/data/web
n=`wc -l /tmp/md5.list` # 由于for循环中的文件的行中不能有空格,所有把循环条件转换为文件的行数
for i in `seq 1 $n` # 取变量的值$n,也要脱义,否则就是$n的值
do
file_name=`sed -n "$i"p /tmp/md5.list |awk ‘{print $2}‘`
md5=`sed -n "$i"p /tmp/md5.list |awk ‘{print $1}‘`
if [ -f $file_name ]
then
md5_b=`md5sum $file_name`
if [ $md5_b != $md5 ]
then
echo "$file_name has changed"
fi
else
echo "$file_name is lost"
fi
done
EOF
scp /tmp/check_md5.sh B:/tmp/
ssh B "/bin/bash /tmp/check_md5.sh" #ssh连接B机器后,运行/bin/bash /tmp/check_md5.sh

3.?批量杀进程

? ?

4.?统计网卡流量

? ?

5.?判断web服务的类型

? ?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读