工作中编写的一些小脚本
发布日期:2021-05-08 23:25:54 浏览次数:19 分类:博客文章

本文共 8642 字,大约阅读时间需要 28 分钟。

#批量处理域名访问时间while read linedoping -c 3 $line|tail -1  |awk -F "/" '{print $5}'>> result/"$line"_result.txt&done < wenzhou_domain.txtsleep 1mwhile read domaindoa=`cat result/"$domain"_result.txt`if [ "$a" = "" ];thenecho unknow >>result.txtelseecho $a    >>result.txtfidone 
$FifoFilerm $FifoFilefor ((i=0;i<=$Thread;i++));do echo;done >&6exec 5<$CurFileNametrap 'kill -9 0;exit 1' 1 2 3 15while read -u5 linedo read -u6 { STATUS_CODE=$(curl -I -o /dev/null -s -w %{http_code} "$line") echo -e "$STATUS_CODE" |tee -a code.txt echo >&6 } &donewait#批量dig取ip#!/bin/bashThread=100CurFileName="domain.txt"FifoFile="$.fifo"mkfifo $FifoFileexec 6<>$FifoFilerm $FifoFilefor ((i=0;i<=$Thread;i++));do echo;done >&6exec 5<$CurFileNametrap 'kill -9 0;exit 1' 1 2 3 15while read -u5 linedo read -u6 { STATUS_CODE=$(dig "$line" A +noall +answer |tail -1|awk '{print $5}' ) echo -e "$line:\t$STATUS_CODE" |tee -a code.txt echo >&6 } &donewait#批量查询端口1)#!/bin/bashThread=100CurFileName="domain.txt"FifoFile="$.fifo"mkfifo $FifoFileexec 6<>$FifoFilerm $FifoFilefor ((i=0;i<=$Thread;i++));do echo;done >&6exec 5<$CurFileNametrap 'kill -9 0;exit 1' 1 2 3 15while read -u5 linedo read -u6 { STATUS_CODE=$(nmap -p80,443 "$line" | grep open ) echo -e "$line\n$STATUS_CODE"|cut -d "/" -f1 |tee -a code.txt echo >&6 } &donewait2)while read domaindonmap -sT $domain | grep open >> result/"$domain"_result.txt &done < domain.txtsleep 5mwhile read Domaindo echo =========$Domain============ >>result.txt cat result/"$Domain"_result.txt >>result.txtdone < domain.txt#监控web服务状态#!/bin/shCheckUrl(){timeout=5fails=0success=0while truedo wget --timeout=$timeout --tries=1 http://blog.chinaunix.net/uid-23929712-id-2650421.html -q -O /dev/null if [ $? -ne 0 ] then let fails=fails+1 else let success=success+1 fi if [ $success -ge 1 ] then echo success Critical="sys is up." echo $Critical|tee|mail -s "$Critical" hejianlai@dnion.com exit 0 fi if [ $fails -ge 2 ] then Critical="sys is down." echo $Critical|tee|mail -s "$Critical" hejianlai@dnion.com exit 2 fi done }CheckUrl#判断系统内存大小#/bin/shFreeMem=`free -m|awk 'NR==3 {print $NF}'`CHARS="Current memory is $FreeMem"if [ $FreeMem -lt 100 ]then echo $CHARS|tee /tmp/messages.txt mail -s "`date +%F-%T`$CHARS" hejianlai@dnion /tmp/tmp.log exec >/tmp/droplist_$(date +%F).log fi donesleep 1mdone#去重输出到原文件#! /bin/bashwhile read gsado{while read yijiazaidoif [ $gsa = $yijiazai ]; thenecho $gsa >>chongfu_domain.txtsed -i "/$gsa/d" vaas.txt#sed -i "/$gsa/d" yijiazai_domain.txtfidone < bukejia_domain.txt}done < vaas.txt#去重输出到新文件#! /bin/bashwhile read https_ddo{while read diyipi_ddoif [ $https_d = $diyipi_d ]; thenecho $https_d >>quchong_and_newfile.txtsed -i "/$https_d/d" diyipi_domain.txtfidone < diyipi_domain.txt}done < https.txt#过滤相同#! /bin/bashwhile read zuihouyipido{while read wangsu666_ddoif [ $wangsu666_d = $zuihouyipi ]; thenecho $wangsu666_d >> qieheidomain.txtfidone < wangsu666domain.txt}done < 161domain.txt#批量取出对应域名url#!/bin/shwhile read linedo cat access.log*|awk '{print $5,$8}'|grep 200|awk '{print $2}'|grep $line|sort -R|head -2 >>rulse.txt done < domain.txt 判断mysql服务是否开启的方法:#!/bin/shecho method1-------------------if [ `netstat -lnt|grep 3306|awk -F "[ :]+" '{print $5}'` -eq 3306 ]then echo "MySQL is Running."else echo "MySQL is Stopped." /etc/init.d/mysqld startfiecho method2-------------------if [ "`netstat -lnt|grep 3306|awk -F "[ :]+" '{print $5}'`" = "3306" ]then echo "MySQL is Running."else echo "MySQL is Stopped." /etc/init.d/mysqld startfi echo method3-------------------if [ `netstat -lntup|grep mysqld|wc -l` -gt 0 ]then echo "MySQL is Running."else echo "MySQL is Stopped." /etc/init.d/mysqld startfiecho method4-------------------if [ `lsof -i tcp:3306|wc -l` -gt 0 ]then echo "MySQL is Running."else echo "MySQL is Stopped." /etc/init.d/mysqld startfiecho method5-------------------[ `rpm -qa nmap|wc -l` -lt 1 ] && yum install nmap -y &>/dev/nullif [ `nmap 127.0.0.1 -p 3306 2>/dev/null|grep open|wc -l` -gt 0 ] then echo "MySQL is Running."else echo "MySQL is Stopped." /etc/init.d/mysqld startfiecho method6-------------------[ `rpm -qa nc|wc -l` -lt 1 ] && yum install nc -y &>/dev/nullif [ `nc -w 2 127.0.0.1 3306 &>/dev/null&&echo ok|grep ok|wc -l` -gt 0 ] then echo "MySQL is Running."else echo "MySQL is Stopped." /etc/init.d/mysqld startfiecho method7-------------------if [ `ps -ef|grep -v grep|grep mysql|wc -l` -ge 1 ] then echo "MySQL is Running."else echo "MySQL is Stopped." /etc/init.d/mysqld startfi判断http服务是否开启的方法:#!/bin/shecho http method1-------------------if [ `netstat -lnt|grep 80|awk -F "[ :]+" '{print $5}'` -eq 80 ] then echo "Nginx is Running."else echo "Nginx is Stopped." /etc/init.d/nginx startfiecho http method2-------------------if [ "`netstat -lnt|grep 80|awk -F "[ :]+" '{print $5}'`" = "80" ] then echo "Nginx is Running."else echo "Nginx is Stopped." /etc/init.d/nginx startfi echo http method3-------------------if [ `netstat -lntup|grep nginx|wc -l` -gt 0 ] then echo "Nginx is Running."else echo "Nginx is Stopped." /etc/init.d/nginx startfiecho http method4-------------------if [ `lsof -i tcp:80|wc -l` -gt 0 ] then echo "Nginx is Running."else echo "Nginx is Stopped." /etc/init.d/nginx startfiecho http method5-------------------[ `rpm -qa nmap|wc -l` -lt 1 ] && yum install nmap -y &>/dev/nullif [ `nmap 127.0.0.1 -p 80 2>/dev/null|grep open|wc -l` -gt 0 ] then echo "Nginx is Running."else echo "Nginx is Stopped." /etc/init.d/nginx startfiecho http method6-------------------[ `rpm -qa nc|wc -l` -lt 1 ] && yum install nc -y &>/dev/nullif [ `nc -w 2 127.0.0.1 80 &>/dev/null&&echo ok|grep ok|wc -l` -gt 0 ] then echo "Nginx is Running."else echo "Nginx is Stopped." /etc/init.d/nginx startfiecho http method7-------------------if [ `ps -ef|grep -v grep|grep nginx|wc -l` -ge 1 ] then echo "Nginx is Running."else echo "Nginx is Stopped." /etc/init.d/nginx startfi echo http method8-------------------if [[ `curl -I -s -o /dev/null -w "%{http_code}\n" http://127.0.0.1` =~ [23]0[012] ]] then echo "Nginx is Running."else echo "Nginx is Stopped." /etc/init.d/nginx startfi echo http method9-------------------if [ `curl -I http://127.0.0.1 2>/dev/null|head -1|egrep "200|302|301"|wc -l` -eq 1 ] then echo "Nginx is Running."else echo "Nginx is Stopped." /etc/init.d/nginx startfiecho http method10-------------------if [ "`curl -s http://127.0.0.1`" = "oldboy" ] then echo "Nginx is Running."else echo "Nginx is Stopped." /etc/init.d/nginx startfi ssh服务开启,关闭脚本#!/bin/shpath=/etc/init.d/sshdif [ $# -ne 1 ] then echo $"usage:$0{start|stop|resatrt}" exit 1fiif [ "$1" = "start" ] then $path start if [ `netstat -lntup|grep sshd|wc -l` -ge 1 ] then echo "sshd is started" exit 0 fielif [ "$1" = "stop" ] then $path stop if [ `netstat -lntup|grep sshd|wc -l` -eq 0 ] then echo "sshd is stop" exit 0 fielif [ "$1" = "restart" ] then $path stop sleep 2 $path start if [ `netstat -lntup|grep sshd|wc -l` -ge 1 ] then echo "sshd is restarted" else echo echo $"usage:$0{start|stop|resatrt}" exit 1 fifi安装lamp,lnmp脚本#!/bin/shpath=/root/scripts[ ! -d "$path" ]&& mkdir $pathcat <
> /etc/hosts.deny fi fidone#执行shell脚本获取oracle数据库信息#!/bin/bashsource ~/.bash_profileget_info (){sqlplus user/password <
= '20181026';--过闸总通行次数select count(*) from api_entry_flow where AEF_ENTRYTIME >= '20181026' and AEF_LINENO<>'1';--万胜围select count(*) from api_entry_flow where AEF_ENTRYTIME >= '20181026' and AEF_LINENO='4';--珠江新城select count (*) from api_entry_flow where AEF_ENTRYTIME >= '20181026' and AEF_LINENO='3';--嘉禾望岗select count(*) from api_entry_flow where AEF_ENTRYTIME >= '20181026' and AEF_LINENO='2';EOF}get_info|grep COUNT -A 3 >result.txta=`cat result.txt|sed -n '3p'|sed s/[[:space:]]//g`b=`cat result.txt|sed -n '8p'|sed s/[[:space:]]//g`c=`cat result.txt|sed -n '13p'|sed s/[[:space:]]//g`d=`cat result.txt|sed -n '18p'|sed s/[[:space:]]//g`e=`cat result.txt|sed -n '23p'|sed s/[[:space:]]//g`echo "智慧安检总注册用户数:${a}过闸总通行次数:${b}万胜围:${c}珠江新城:${d}嘉禾望岗:${e}" >zhihuianjian.txt

 

上一篇:Mysql高可用架构(主从同步)
下一篇:sed运用

发表评论

最新留言

哈哈,博客排版真的漂亮呢~
[***.90.31.176]2025年03月31日 15时44分46秒