shell练习
羊村一棵草
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
shell习题6
shell习题6题: 监控http80端口,发现服务down了之后,启动程序#!/bin/bashwhile : do http=`netstat -ntlp|grep 80|grep http|wc -l` if [ $http -eq 0 ];then echo "http server is down" >> error.txt systemctl start httpd else sleep 60 fidone...原创 2021-12-31 15:32:27 · 536 阅读 · 0 评论 -
shell习题5
shell习题5题:备份某个文件下所有txt文件,进行打包备份,还原操作目录下创建10个文件[root@localhost test]# ls file/10.txt 1.txt 2.txt 3.txt 4.txt 5.txt 6.txt 7.txt 8.txt 9.txt[root@localhost test]# ls123_20211231100740 20211231100740.zip file[root@localhost test]# cat bak.s原创 2021-12-31 10:20:38 · 216 阅读 · 0 评论 -
shell习题4
shell习题4题:监测服务器是否存活#!/bin/bash#设置服务器ip地址ip=10.155.155.101#每隔3分钟去ping服务器是否存活,如果不存活则输入报错到error.txtwhile :do packet=`ping -c 3 10.155.155.101|grep packet|awk '{print $6}'|sed 's/%//g'` if [ $packet -eq 0 ];then echo "$ip baocuo" >> /home/yy/原创 2021-12-30 16:53:41 · 264 阅读 · 0 评论 -
shell习题3
shell习题3题:计算所有进程占用mem的和#!/bin/bash#定义变量sum=0sum=0#ps -aux获取所有在运行的进程的内存,获取的内存为KBfor mem in `ps -aux|awk '{print $6}'|grep -v '^0'|grep -v '^[a-Z]'` do sum=$[$sum+$mem]done#把相加的内存从KB转为MB除以1024m=`expr $sum / 1024`#输出内存信息echo "this server mem原创 2021-12-30 15:38:46 · 744 阅读 · 0 评论 -
shell习题2
shell习题2统计linux中登录失败的ip和次数cat /var/log/secure-20211227 | head -10Dec 23 15:48:55 localhost sshd[74110]: Accepted password for root from 10.155.155.1 port 50961 ssh2Dec 23 15:48:55 localhost sshd[74110]: pam_unix(sshd:session): session opened for user r原创 2021-12-29 17:07:14 · 369 阅读 · 0 评论 -
shell练习1
shell习题1要求:请按照这样的日期格式(xxxx-xx-xx)每日生成一个文件,例如今天生成的文件为)2021-12-29.log, 并且把磁盘的使用情况写到到这个文件中,(不考虑cron,仅仅写脚本即可)cat date.sh#!/bin/bashwhile : dotoday_date=`date +%F` #查看当天的日期file_date=`ls $today_date.log | wc -l` #查看当前文件夹是否有以当天日期命名的log文件 if [ $fil原创 2021-12-29 16:42:31 · 320 阅读 · 0 评论 -
多线程执行shell
多线程执行shell实验情况,需要查看哪些服务器可以ping通,哪些服务器可以登录,把网络不通的,和登录失败的都列出来。#!/bin/bash#查看是否安装sshpass服务ssh_pass=rpm -qa|grep sshpass|wc -l#如果结果等于0,代表没有安装,则进行安装sshpass服务if [ $ssh_pass -eq 0 ]thenrpm -ivh ./sshpass-1.06-2.el7.x86_64.rpmfi#对于未连接过的主机,对sshd进行优化echo原创 2021-12-24 09:47:20 · 992 阅读 · 0 评论 -
xhell练习题
1、每日生成一个文件要求:请按照这样的日期格式(xxxx-xx-xx)每日生成一个文件,例如今天生成的文件为)2019-01-29.log, 并且把磁盘的使用情况写到到这个文件中,(不用考虑cron,仅仅写脚本即可)#!/bin/bashd=`date +%F`mkdir /tmp/log/while : do logfile=$d.log df -...原创 2019-01-30 10:59:37 · 662 阅读 · 0 评论
分享