1,备份常用的脚步:
脚步一
#!/bin/sh mkdir -p /backup/`date +%Y%m%d` cd /opt/ tar -czvf /backup/`date +%Y%m%d`/m_`date +%s`.tar.gz m/
脚本二:
#! /bin/bash mkdir -p /backup/`date +%Y%m%d` cd /opt/ tar -czvf /backup/`date +%Y%m%d`/m_`date +%Y%m%d%H%M%S`.tar.gz --exclude=files --exclude=*.jar m/ tar -czvf /backup/`date +%Y%m%d`/home_`date +%Y%m%d%H%M%S`.tar.gz --exclude=files --exclude=*.jar home/
脚本三:
#! /bin/bash mkdir -p /backup/webapp/`date +%Y%m%d` cd /gjbweb/ #tar -czvf /backup/`date +%Y%m%d`/webapp_`date +%Y%m%d%H%M%S`.tar.gz --exclude=files --exclude=*.jar webapp/ tar -czvf /backup/webapp/`date +%Y%m%d`/webapp_`date +%Y%m%d%H%M%S`.tar.gz --exclude=files --exclude=appFiles --exclude=zipfstmp* webapp/
2,常用压缩脚本:
#! /bin/bash cd /gjbweb/tomcat/logs find /gjbweb/tomcat/logs -type f -mtime +2|grep -v "tar.gz"|grep -v "archive.sh"|while read line do lname=`basename $line` tar -czvf $lname".tar.gz" $lname --remove-files done
#! /bin/bash cd /lqbo/backup/logs find /lqbo/backup/logs -type f|grep -v "tar.gz"|grep -v "archive.sh"|while read line do lname=`basename $line` tar -czvf $lname".tar.gz" $lname --remove-files done
#! /bin/bash #Power by lqb date=`date +%Y%m%d --date="-1 day"` #date=`date +%Y-%m-%d` logfile="/home/nginx/access.log" logdir=/home/nginx/logs pid=`cat /run/nginx.pid` if [ ! -d $logdir ]; then mkdir -p $logdir fi /bin/mv $logfile $logdir/access_.log kill -HUP $pid cd /home/nginx/logs find /home/nginx/logs -type f -mtime +2|grep -v "tar.gz"|grep -v "archive.sh"|while read line do lname=`basename $line` tar -czvf $lname".tar.gz" $lname --remove-files done
网络丢包监控脚本
# cat checkUser.sh #!/bin/bash export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin log_time=`date +"%Y-%m-%d-%H-%M-%S"` for i in `cat /root/bin/country.txt | grep -v '^$' | awk -F ':' '{print $1}'`;do #echo $i surecountry=`cat /tmp/checkUserLag.txt | grep $i` if [ "$?" -eq 0 ];then #echo $surecountry Weightnum=`cat /root/bin/country.txt | grep $i | awk -F'#' '{print $1}' | awk -F ':' '{print $2}'` Weightloss=`cat /root/bin/country.txt | grep CN | awk -F'#' '{print $1}' | awk -F ':' '{print $3}'` Content=`cat /tmp/checkUserLag.txt | grep $i` #echo $Content Numpre=`cat /tmp/checkUserLag.txt | grep $i | awk -F ',' '{print $3}' | awk -F "[()]" '{print $2}' | cut -d % -f 1 | cut -d . -f 1` Losspre=`cat /tmp/checkUserLag.txt | grep $i | awk -F ',' '{print $4}' | awk -F ':' '{print $2}' | cut -d % -f 1 | cut -d . -f 1` echo $i weight: $Weightnum $Weightloss waring : $Numpre $Losspre if [ "" -ne "0" -o "" -ne "0" ];then #echo $i $Weightnum $Weightloss $Numpre $Losspre if [ "" -ge "" -o "" -ge "" ];then echo "server3 .Contact CQ or Jacky" | skypealarm -c res=$? echo >> /tmp/UserLag.log echo " " >> /tmp/UserLag.log #echo "$Numpre > $Weightnum or > " else echo "server3 " | skypealarm -w res=$? echo >> /tmp/UserLag.log echo " " >> /tmp/UserLag.log #echo "$Numpre < $Weightnum or < " fi fi fi done
重设置的文件:
#cat /root/bin/country.txt KR:10:10 HK:10:10 CN:10:15 JP:10:10 TW:10:10
丢包统计和访问有延迟的用户比例:
cat /tmp/checkUserLag.txt
3,定时任务
[root@iZ23iod5vslZ ~]# crontab -l 30 1 * * * /opt/logs/archive.sh >>/opt/logs/archive.log 30 5 * * * /home/update/tool/archive.sh >>/opt/logs/archive.log 10 5 * * * /usr/sbin/ntpdate -u >>/opt/logs/ntp.log 15 5 * * * cd /usr/tomcat/logs && find . -type f -mtime +3 -exec mv {} /data/logs/ \; 20 5 * * * cd /opt/logs && find . -type f -mtime +3 -exec mv {} /data/logs/ \; 23 4 * * * cd /guojinbao/tomcat/logs/ && find . -type f -mtime +5 -exec mv {} /data/logs/ \;
winods常用检索批处理
(1)检查D:\新建文件夹\east\target目录下文件是否更新批处理脚步
@echo off setlocal enabledelayedexpansion for /f "delims=" %%i in (codelist_pc.txt) do ( ##读取codelist_pc.txt文件 set webpath=%%i if /i "!webpath:~0,19!"=="east-1.0.0-SNAPSHOT" ( #####east-1.0.0-SNAPSHOT字符个数19如果是其他的数可以更改相应字符数。 set webpath=!webpath:/=\! dir D:\新建文件夹\east\target\!webpath! |findstr "^[0-9][0-9][0-9][0-9]/[0-9][0-9]/[0-9][0-9]" )else echo !webpath! REM echo !webpath! rem if not exist D:\新建文件夹\east\target\!webpath! echo ERROR:NOT FUND! ) pause
codelist_pc.txt文件内容:
east-1.0.0-SNAPSHOT/landing.html east-1.0.0-SNAPSHOT/newMan.shtml east-1.0.0-SNAPSHOT/WEB-INF/lib/ecc_2.11-1.0.jar
执行的结果为:
(2)批量备份打包列表的文件并建立相应的目录
@echo off cd /d d:\upload title Echo date if format 'yyyy-MM-dd HH:mm:ss' for /f "tokens=1 delims=/ " %%j in ("%date%") do set d1=%%j for /f "tokens=2 delims=/ " %%j in ("%date%") do set d2=%%j for /f "tokens=3 delims=/ " %%j in ("%date%") do set d3=%%j for /f "tokens=1 delims=: " %%j in ("%time%") do set t1=%%j for /f "tokens=2 delims=: " %%j in ("%time%") do set t2=%%j for /f "tokens=3 delims=:. " %%j in ("%time%") do set t3=%%j ::mkdir D:\upload\%d1%-%d2%-%d3% echo move and backup: if exist D:\upload\east-1.0.0-SNAPSHOT move east-1.0.0-SNAPSHOT backup\east-1.0.0-SNAPSHOT_%d1%-%d2%-%d3%_%t1%-%t2%-%t3% if exist D:\upload\codelist_pc.txt copy codelist_pc.txt backup\east-1.0.0-SNAPSHOT_%d1%-%d2%-%d3%_%t1%-%t2%-%t3% ::rd /S /Q D:\upload\east-1.0.0-SNAPSHOT echo begin to copy: setlocal enabledelayedexpansion for /f "delims=" %%i in (codelist_pc.txt) do ( set webpath=%%i if /i "!webpath:~0,19!"=="east-1.0.0-SNAPSHOT" ( set webpath=!webpath:/=\! set webpath=!webpath: =! set webpath=!webpath:=! rem echo webpath:!webpath! set sourcepath=%%~dpi set sourcepath=!sourcepath:/=\! if not exist !sourcepath! md !sourcepath! if exist D:\新建文件夹\east\target\!webpath! copy D:\新建文件夹\east\target\!webpath! D:\upload\!webpath! ) ) rem mkdir %%~dpi rem call pack.bat %%i rem if exist D:\新建文件夹\east\target\%%i copy D:\新建文件夹\east\target\%%i D:\upload\%%i pause
(3)常用的脚本---netstat和awk结合统计TCP状态
netstat -n|awk '/^tcp/ {++state[$NF]} END {for(key in state) print key," \t" ,state[key]}'
[root@iZ237lzm354Z ~]# netstat -n|awk '/^tcp/ {++state[$NF]} END {for(key in st ate) print key," \t" ,state[key]}' LAST_ACK 28 SYN_RECV 6 CLOSE_WAIT 5 ESTABLISHED 1709 FIN_WAIT1 88 FIN_WAIT2 657 TIME_WAIT 1052