版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
chsh用户名s新> 用户变量由系统用户来生成和定义,变量的值可以通过命令“echo$<变量名>”查看。2>&12>&1如ls/usr/share/docout.txt2>&1&>&>如lsusr/share/doc&>out.txt ifif]if] root@localhost:~#root@localhost:~#lsroot@localhost:~#root@localhost:~#lsls:cannotaccess/usr/bin/share:Nosuchfileordirectoryroot@localhost:~#echo$?2 答:在if-then中使用测试命令(-gt等)if[$x-gt$y]echo“xisgreaterthanecho“yisgreaterthan 答:break命令一个简单的用途是退出执行中的循环。我们可以在while和until循环中使用break出循环。 casecase变量 答:如同for循环,while循环只要条件成立就重复它令块。不同于for循环,while循环会不断迭whilewhile]命令 oda+x bang。它的意思是命令通过/bin/bash forforin 答:使用'-x'参数(sh-xmyscript.sh)可以调试s 。另一个种方法是使用‘-nv’参数(sh-nv 答:下面的表列出了Bourne 第个命令行参数 -d-e-f-r-s-w-x 如果文件存在,返回e #Thisisaecho“Iamloggedinas答:read命令可以来自终端(使用键盘)的数据。read命令得到用户的输入并置于你给出的变量中。例子如下:echo‘Pleaseenteryourreadecho“MyNameis#MyNameisunset变量名##expr5+test=$[16test=$[16+4];test=$[16+答:do-while语句类似于while语句,但检查条件语句之前先执行命令(LCTT译注:意即至少执行一{while条件 答:函数是拥有名字的代码块。当我们定义代码块,我们就可以在我们的调用函数名字,该块就会被执行。示例如下所示:$$diskusage(){df-h; function函数名{[return}1-24 方法方法#echo$RANDOM|md5sum|cut-c1-8方法#opensslrand-base644方法#cat/proc/sys/kernel/random/uuid|cut-c1-8方法方法#echo$RANDOM|cksum|cut-c1-方法#opensslrand-base644|cksum|cut-c1-方法#date+%N|cut-c1-方法方法functionecho_color()if[$1=="green"];elif[$1=="red"];thenecho-e}方法function{case$1inecho-eecho-eecho"Example:echo_colorred}使用方法:echo_colorgreenif[$1=="green"];elif[$1=="red"];thenecho-e}#如果用户文件存在并且大小大于0if[-s$USER_FILE];mv$USER_FILE${USER_FILE}-echo_colorgreen"$USER_FILEexist,rename${USER_FILE}-echo"----------------">>forUSERinuser{1..10};if!id$USER&>/dev/null;PASS=$(echo$RANDOM|md5sum|cut-c1-8)useradd$USERecho$PASS|passwd--stdin$USER&>/dev/nullecho-e"$USER\t$PASS">>$USER_FILEecho"$USERUsercreateecho_colorred"$USERUseralreadyifrpm-qsysstat&>/dev/null;thenecho"sysstatisnotPORT_C=$(ss-anu|grep-cPS_C=$(ps-ef|grepntpd|grep-vcgrep)if[$PORT_C-eq0-o$PS_C-eq0];echo"内容"|mail-s IP_LIST="forIPin$IP_LIST;dowhile[$NUM-le3];if-c1$IP>/dev/null;thenecho"$IPissuccessful."#echo isfailureletif[${#FAIL_COUNT[*]}-eq3echo"${FAIL_COUNT[1]} unsetFAIL_COUNT[*]IP_LIST="forIPin$IP_LIST;dofor((i=1;i<=3;i++)); -c1$IP>/dev/null;thenecho"$IP#echo"$IP isfailure$i"letFAIL_COUNT++if[$FAIL_COUNT-eq3];then is _success_status()if-c1$IP>/dev/null;thenecho"$IPissuccessful."}IP_LIST="forIPin$IP_LIST;echo"$IPisDATE=$(date+%F"IP=$(ifconfigeth0|awk-F'[:]+''/inetaddr/{print$4}')#只支持CentOS6 if!whichvmstat&>/dev/null;echo"vmstatcommandnofound,Pleaseinstallprocpspackage."exit1US=$(vmstat|awk'NR==3{print$13}')SY=$(vmstat|awk'NR==3{print$14}')if[$USE-ge50];thenecho"Host:$IPProblem:CPUutilization"|mail-s"CPUMonitor"DATE=$(date+%F"IP=$(ifconfigeth0|awk-F'[:]+''/inetaddr/{print$4}') -m|awk'/Mem/{print$2}') =$(($TOTAL-#内存小于1G发 if[$ -lt1024];thenecho"Host:$IPProblem:"|mail-s"MemoryMonitor"DATE=$(date+%F"IP=$(ifconfigeth0|awk-F'[:]+''/inetaddr/{print$4}') foriin$PART_USE;doPART=$(echo$i|cut-d"="-f1)USE=$(echo$i|cut-d"="-f2)MOUNT=$(echo$i|cut-d"="-f3)if[$USE-gt80];thenecho"Host:$IPTotal:Problem:"|mail-s"DiskMonitor"forIPin$(awk'/^[^#]/{print$1}'$HOST_INFO);doUSER=$(awk-vip=$IP'ip==$1{print$2}'$HOST_INFO)PORT=$(awk-vip=$IP'ip==$1{print$3}'ssh-p$PORT$USER@$IP'df-h'>USE_RATE_LIST=$(awk'BEGIN{OFS="="}/^\/dev/{print$1,int($5)}'$TMP_FILE)forUSE_RATEin$USE_RATE_LIST;doif[$USE_RATE-ge80];方法方法check_url()HTTP_CODE=$(curl-o/dev/null--connect-timeout3-s-w"%{http_code}"$1)if[$HTTP_CODE-ne200];thenecho"Warning:$1Access}方法check_url()ifwgetT10tries=1spider$1dev/null2>&1;thenecho"Warning:$1Access}方法1:利用循环技巧,如果成功就跳出当前循环,否则执行到最后行方法1:利用循环技巧,如果成功就跳出当前循环,否则执行到最后行HTTP_CODE=$(curl-o/dev/null--connect-timeout3-s-w"%{http_code}"$1)if[$HTTP_CODE-eq200];then} forURLin$URL_LIST;docheck_url$URLcheck_url$URLcheck_url$URLecho"Warning:$URLAccessforURLin$URL_LIST;"forfor((i=1;i<=3;i++));HTTP_CODE=$(curl-o/dev/null--connect-timeout3-s-wif[$HTTP_CODE-ne200];thenletFAIL_COUNT++if[$FAIL_COUNT-eq3];echo"Warning:$URLAccessforURLin$URL_LIST;dowhile[$NUM-le3];"HTTP_CODE=$(curl-o/dev/null--connect-timeout3-s-wif[$HTTP_CODE-ne200];thenletNUM++if[${#FAIL_COUNT[*]}-eq3];thenunset IO_SQL_STATUS=$(mysqlu$USERp$PASSWDeshowslavestatus\G|awkF:'/Slave_.*_Running/{gsub(":",":");print$0}')#gsub去除冒号后面的空格foriin$IO_SQL_STATUS;doif["$THREAD_STATUS"!="Yes"];echo"Error:MySQLMaster-Slave$THREAD_STATUS_NAMEstatus DATE=$(dateABNORMAL_IP=$(tail-n5000access.log|grep$DATE|awk'{a[$1]++}END{for(iina)if(a[i]>100)printi}')forIPin$ABNORMAL_IP;if[$(iptables-vnL|grep-c"$IP")-eq0];theniptables-IINPUT-s$IP-jDROP9]+/,"",$5);{a[$5]++}}END{for(iina)if(a[i]>100)printi}')forIPin$ABNORMAL_IP;if[$(iptables-vnL|grep-c"$IP")-eq0];theniptables-IINPUT-s$IP-jDROPDATE=$(date+"%a%b%e%H:%M")#星期月天时分%e单数字时显示7,而%d显示07forIPin$ABNORMAL_IP;if[$(iptables-vnL|grep-c"$IP")-eq0];theniptables-IINPUT-s$IP-jDROPDATE=$(date+"%b%d'/Failed/{a[$(NF-3)]++}END{for(iina)if(a[i]>5)printi}')"forIPin$ABNORMAL_IP;doif[$(iptables-vnL|grep-c"$IP")-eq0];theniptables-AINPUT-s$IP-jDROPecho"$(date+"%F%T")-iptables-AINPUT-s$IP-jDROP">>~/ssh-login-VALID_CHECK=$(echo$IP|awk-F.'$1<=255&&$2<=255&&$3<=255&&$4<=255{printifecho$IP|grep-E"^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-{1,3}$">/dev/null;if[$VALID_CHECK=="yes"];thenecho"$IPavailable."echo"$IPnotecho"Format}check_ipcheck_ipif[[$IP=~^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$]];FIELD1=$(echo$IP|cut-d.-f1)FIELD2=$(echo$IP|cut-d.-f2)FIELD3=$(echo$IP|cut-d.-f3)FIELD4=$(echo$IP|cut-d.-f4)if[$FIELD1-le255-a$FIELD2-le255-a$FIELD3-le255-a$FIELD4-255];echo"$IPecho"$IPnotecho"Format}}check_ipcheck_ipVALID_CHECK=$(echo$IP|awk-F.'$1<=255&&$2<=255&&$3<=255&&$4<=255{printifecho$IP|grep-E"^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0->/dev/null;if[$VALID_CHECK=="yes"];thenreturn0return1echo"Formaterror!Pleaseinputagain."return1}whiletrue;read-p"PleaseenterIP:"IPcheck_ip$IP[$?-eq0]&&break||if[[$1=~^[0-9]+$]];thenecho"IsNumber."echo"Noif[$1-gt0]2>/dev/null;thenecho"IsNumber."echo"Noecho$1|awk{print$0~/^[0-9]+$/?"IsNumber.":"NoNumber12.14forFILEin$(find$DIR-typef);ifgrep$KEY$FILE&>/dev/null;thenecho"-->$FILE" forFILEin$(find$DIR-typef);ifgrep$KEY$FILE&>/dev/null;thenecho"-->$FILE"Q:39,将新创建的文件名追加到日志 inotifywait-mq--format%f-ecreate$MON_DIR|\whilereadfiles;dofunction{localNUMARRAY_LENGTHNUM=0forNIC_NAMEin$(ls/sys/class/net|grep-vE"lo|docker0");doNIC_IP=$(ifconfig$NIC_NAME|awk-F'[:]+''/inetaddr/{print$4}')if[-n"$NIC_IP"];thenif[-n"$NIC_IP"];thenletif[$ARRAY_LENGTH-eq1];thenreturnelif[$ARRAY_LENGTH-eq0];thenecho"Noavailablenetworkcard!"exit1forNICin${NIC_IP_ARRAY[*]};doecho$NICwhiletrue;#read-p"Pleaseenterlocalusetonetworkcardname:"forNICin${NIC_IP_ARRAY[*]};doif[$NIC_NAME=="$INPUT_NIC_NAME"];thenreturnecho"Notmatch!Pleaseinput}traffic_unit_conv(){localif[$traffic- ];elif[$traffic-lt ];thenprintf"%.1f%s""$(($traffic/1024))"}echo-e" whiletrue;OLD_IN=$(awk-F'[:]+''$0~"'$NIC'"{print$3}'/proc/net/dev)sleep1NEW_IN=$(awk-F'[:]+''$0~"'$NIC'"{print$3}'sleep1Q:42、MySQLcd"ifmysqldump-h$HOST-u$USER-p$PASS--single-transaction--routines--triggersB$DB>$SQL_FILE;zip$BAK_FILE$SQL_FILE&&rm-f$SQL_FILEif[!-s$BAK_FILE];thenecho"$DATE内容"|mail-s "echo"$DATE内容"|mail-s "find$BACKUP_DIR-name'*.zip'-ctime+14-execrm{}场景:使用源码包安装Nginx不含带服务管理,也就是不能使用"servicenginxstart"或"/etc/init.d/nginxstart",所以写了以下的服务管理。#Description:OnlysupportRedHat./etc/init.d/functionsif[-z"$PID"];thenstop()$DAEMON-sstopsleep1[!-f$PID]&&action"* $NAME"/bin/true||action"*$NAME"}start()sleep[-f$PID]&&action"*Starting$NAME"/bin/true||action"*$NAME"}reload()$DAEMON-s}test_config()$DAEMON-}case"$1"if[!-f$PID];then
echo"$NAMEisrunning..."exit0if[-f$PID];then
echo"$NAMEnotrunning!"exit0if[!-f$PID];echo"$NAMEnotrunning!"
[-f$PID]&&echo"$NAMEisrunning..."||echo"$NAMEnot|status}"exit :{##catWeb0rootDB1rootwhiletrue;doselectNAMEin$(awk'{print$1}'$HOST_FILE)quit;do[${NAME:=empty}=="quit"]&&exit0IP=$(awk-vNAME=${NAME}'$1==NAME{print$2}'$HOST_FILE)USER=$(awk-vNAME=${NAME}'$1==NAME{print$3}'$HOST_FILE)PORT=$(awk-vNAME=${NAME}'$1==NAME{print$4}'if[$IP];echo"Name:$NAME,IP:sshoStrictHostKeyChecking=nop$PORTiid_rsa$USER@$IP#echo"Inputerror,Pleaseenteragain!"Q:45从FTP服务器文if[$#-ne1];echo"Usage:$0dir=$(dirname$1)ftpnv nopen0ftp服务器useradminpassword cd$dirwhile[$COUNT-le5];if$INT=~^[0-9]+$thenecho"输入必须是整数!"exitelif$INTgt100thenecho"输入必须是100以内!"exit1[$MIN-lt$INT]&&MIN=$INT[$MAX-gt$INT]&&MAX=$INTletCOUNT++echo"SUM:$SUM"echo"MIN:$MIN"echo"MAX:forforiin$(echo"456");doevala$i=$iecho$a4$a5foriin$(evalecho$*);do letnum+=1echo$node1$node212arr=(456)arr=(456)INDEX3=$(echo#lsarticle_1.htmlarticle_2.htmlforforfilein$(ls*html);domv$file#mv$file$(echo$file|sed-r's/.*(_.*)/bbs\1/')#mv$file$(echo$file|echobbs_$(cut-d_-f2)forforfilein$(find.-maxdepth1-name"*html");domv$filebbs_${file#*_}##renamearticlebbs ##find.-name"*.html"-execdu-k{}\;|awk'{sum+=$1}END{printforforsizein$(ls-l*.html|awk'{print$5}');doPORT="222580forPORTin$PORT;ifecho&>/dev/null>/dev/tcp/$HOST/$PORT;thenecho"$PORTopen"echo"$PORTQ:51Expect实现SSH expect<<EOFsettimeoutexpect{"password:"{send"$PASS\r"}}expect"$USER@*"{send"$1\r"}expect"$USER@*"{send"exit\r"}expecteofexpect-cexpect{\"(yes/no)\"{send\"yes\r\";\"password:\"{send\"$PASS\r\";\"$USER@*\"{send\"df-h\rexit\r\";#catlogin.exp#catlogin.expsetip[lindex$argv0]setuser[lindex$argv1]setpasswd[lindex$argv2]setcmd[lindex$argv3]if{$argc!=4}{puts"Usage:expectlogin.expipuserpasswd"exit1}settimeout30expect{"password:"{send"$passwd\r"}}expect"$user@*"{send"$cmd\r"}expect"$user@*"{send"exit\r"}expecteofforipin$(awk'{print$1}'$HOST_INFO)user=$(awk-vI="$ip"'I==$1{print$2}'$HOST_INFO)pass=$(awk-vI="$ip"'I==$1{print$3}'$HOST_INFO)expectlogin.exp$ip$user$pass$1#catuser_info.txt#catuser_info.txt#cat1718内容格式:IPUserPasswordPortforIPin$(awk'/^[^#]/{print$1}'$OLD_INFO);doUSER=$(awk-vI=$IP'I==$1{print$2}'$OLD_INFO)PASS=$(awk-vI=$IP'I==$1{print$3}'$OLD_INFO)PORT=$(awk-vI=$IP'I==$1{print$4}'NEW_PASS=$(mkpasswd-l8)# echo expect-c$PORT">>settimeout2expect\"(yes/no)\"{send\"password:\"{send\"$USER@*\"{send\"echo\'$NEW_PASS\'|passwd--stdin$USER\r#catnew_pass.txt17#catnew_pass.txt1718##awk'BEGIN{for(n=0;n++<9;){for(i=0;i++<n;)printfi"x"n"="i*n"";printforfor((i=1;i<=9;i++));getopts是一个解析选项参数的工具。whilegetopts:f:n:option;docase$optionin[!-f$FILE]&&echo"$FILEFilenotexist!"&&sed-n"${OPTARG}p"echo"Usage:$0-f<file_path>-n<line_number>"echo"-f,--file specifiedfile"echo"-n,--line-number exit1作者:Q:54IP=`ifconfigeth0|head-2|tail-1|awk'{print$2}'|awk-F":"ZW=`ifconfigeth0|head-2|tail-1|awk'{print$3}'|awk-F":"GW=`route-n|tail-1|awk'{print$2}'`DNS=`head1/etc/resolv.conf|awk{print$2}'`echo'此机IP地址是'$IPecho'此机网关是'$GWecho此机DNS是 SIZE=`du-shecho"Date:$DAY">>echo"DataSize:$SIZE">>cd/opt/dbbak&>/dev/null||mkdirtarzcf/opt/dbbak/mysqlbak-${DAY}.tar.gz/var/lib/mysql/tmp/dbinfo.txtrm-f5523*/3** #mkdir/mysqlbak#mkdir/mysqlbinlog#mkdir/mysqlbak#mkdir/mysqlbinlogcd/s#viwebdb.shmysql-hlocalhost-uroot-p-e"flushlogs" od+xwebdb.sh#crontab-3023**7 只检查服务vsftdhttpdsshdcrond、mysl如果不是这5个中的服务,就提示用户能够检查的服务名并退出如果服务是运行着的就输出"服务名isrunning"readp请输入你的服务名if[$service!='crond'-a$service!='httpd'-a$service!='sshd'-a!='mysqld'-a$service!='vsftpd'];thenecho只能够检查'vsftpd,httpd,crond,mysqld,sshd"exit5service$servicestatus&>if[$?-eq0];thhenecho"服务 ifif[-z$1echo"Youmastspecifyaservername!"echo"Usage:`basename$0`servername"exit2if[$1=="crond"]||[$1=="mysql"]||[$1=="sshd"]||[$1==]||[$1=="vsftpd"];thenservice$1status&>/dev/nullif[$?-eq0];thenecho"Usage:`basename$0`serverecho"Butonlycheckforvsftpdhttpdsshdcrondmysqld"&&exit2Q:58foriin`seq1012`-c3$ip$i&>/dev/nullif[$?-eq0];then date>>/tmp/ip.txtecho 的主机台数有[root@test1[root@test1scripts]#vimread-p"Enterawebsitedirectory:"webdir echo read-p"Enterdbusername:"dbuserecho$dbuserread-sp"Enterdbuserpassword:"read-p"Enterdbname:"dbnameecho$dbnameread-p"Enterdbtablepre:"dbtablepreecho$dbtablepreGlobalphp=`grepGlobalphp=`grep"tablepre*"th/config_global.php|cut-d"'"-Ucenterphp=`grep"UC_DBTABLEPRE*"$W awk-F"'"'{print$1}'`if[$dbtablepre==$Globalphp]&&[$dbtablepre==$Ucenterphpread-p"Enteryouname:"usersetecho$usersetResult=`$MYsql-u$dbuser-p$dbpass$dbname-e"selectusernamefrom$Prewhereusername='$userset'\G"|cut-d''-f2|tail-1`echoif[$userset==$Resultread-p"Enteryourpassword:"userpasspassnew=`echo-n$userpass|opensslmd5|cut-d''-$MYsql-u$dbuser-p$dbpass$dbname-e"update$Presetpassword='$passnew'whereusername='$userset';"$MYsql-u$dbuser-p$dbpass$dbname-e"flushecho"$usersetisnotrightuser!"exit1exit[root@test1[root@test1scripts]#vimnetstat-tulnp|grep:3306>/dev/nullif[$?-eq0];thenecho服务正在运行-c300&>/dev/nullif[$?-eq0];thenecho网络连接正常echo网络连接失败mysql-h00-uroot-p123456&>/dev/nullif[$?-eq0];thenIO=mysql-uroot-p123-e"showslavestatus\G"|grepSlave_IO_Running|awk'{print$2}'>/dev/nullSQL=mysql-uroot-p123-e"showslavestatus\G"|grepSlave_SQL_Running|awk'{print$2}'/dev/nullif[IO==Yes]&&[SQL==Yesecho“IOandSQL连接成功echoIO线程和SQL线程连接失败"ss_ss_row=`cat_list|wc- -H'Content-Type:application/json "msgtype":"text","text":{"content":}apache_check_80(){ip=$1HTTP_CODE=`curl-o/dev/null-s-w"%{http_code}"if[$HTTP_CODE!=200trans_text\n$ipApache服务器状态异常,网页返回码'"$HTTP_CODE"' }ss_row=`cat_list|wc-fortempin`seq1 Ip_Addr=`cat_list|head-n$temp|tail-napache_check_80sleepwhile["$ip_num"-le"$(expr${#remote_ip[@]}-l)"]ssh"$remote_user"@"${remote_ip[$ip_num]}"df-h>/tmp/diskcheck_tmpgrep'^/dev/*'/tmp/diskcheck_tmp|awk'{print$5}'|sed's/\%//g'while["$read_num"-le$(wc-l</tmp/diskcheck_num_tmp)]size=$(sed-n"$read_num"'p'/tmp/diskcheck_num_tmp)if["size"-gt"$FSMAX"]$(grep'^/dev/*'/tmp/diskcheck_tmp|sed-n>$(echo${remote_ip[$ip_num]})>>$(mail-s"diskcheck_alert"adminread_num=$(expr$read_num+ip_num=$(expr$ip_num+ IP=`ifconfigeth0|grep"inetaddr"|cut-f2-d":"|cut-f1-d""`SPACE=`df-hP|awk'{printint($5)}'`if[$SPACE-ge90]echo"$IP服务器磁盘空间使用率已经超过90%,请及时处理。"|mail-s"$IP:网络技术干货圈#!#!ftp-n<<END_FTPopenusertest//用户名prompt DAY=`dateSIZE=`du-shecho"Date:$DAY">>echo"DataSize:$SIZE">>cd/opt/dbbak&>/dev/null||mkdirtarzcf/opt/dbbak/mysqlbak-${DAY}.tar.gz/var/lib/mysql/tmp/dbinfo.txtrm-f5523*/3**Q:66.declaredeclare-aforiin`seq4049`ary[$i]="echoecho-en"\e[$i;5mdeclare-aforsin`seq110000`foriin`seq4049`ary[$i]="echo-en"\e[$i;5mQ:67.for((i=1;i<12;i++))if[[$i-le6]]for((j=$((12-i));j>i;j--))echo-n"for((m=1;m<=$((2*i-1));m++))echo-n"*echo""elif[[$i-gt6]]for((j=$((12-n));j>n;j--))echo-n"for((m=1;m<=$((2*n-1));m++))echo-n"*echo#!/usr/bin/expect#!/usr/bin/expect-setipaddress[lindex$argvsetpasswd[lindex$argvsettimeoutspawnssh-copy-idexpect"yes/no"{send"yes\r";exp_continue"password:"{send"$passwd\r"}#expect#send"mkdir-p#send#expect#i#命令运行完你要期待个结果结果就是返回提示符了(是#或者"THHP_CODE=`curl-o/dev/null-s-w"%{http_code}"if[$HTTP_CODE!=200echo-e"apache[-f$log]||touchfunction{ip=`echo$line|awk'{print$2}'`ifif[$count-gt100]&&[`iptables-L-n|grep|wc-l`-lt1iptables-IINPUT-s$ip-jDROPecho-e"$list}function{netstat-an|grep"EST"|awk-F'[:]+''{print$6}'|sort|uniq-sleep180} function{if!rpm-qa|grep-q"^$1"yuminstall$1if[$?-eq0]echo-e"$iinstallisecho-e"$1installecho-e"yianzhuang!}forinsinmysqlphphttpdMyInstall declare-aforiin`seq110`echo-e"Array_1:if[${array[$y]}-gt${array[$y+1]}]echo-e"Array_2:arr=("|""/""-""\\"while[$i-le100]letprintf"[%-100s][%d%%][\e[43;46;1m%c\e[0m]\r""$bar""$i""${arr[$index]}"leti++letindex++printf.forUnamein`cat/root/useradd.txt|gawk'{print$1}'`if[$?-eq0]echo-e"这个账号已存在!来源: forUpasswdin`cat/root/useradd.txt|gawk'{print$2}'`useradd$Uname&>echo"$Upasswd"|passwd--stdin$Uname&>/dev/nullif[$?-eq0]echoe创建失败declare-aforiin`seq020`ary[$i]="sleep1while:;dospeedday='date+%m"-"%d'speedrx_before='ifconfigspeedrx_before='ifconfigeth0|sed-n"8"p|awk'{print$2}'|cut-c7-'speedtx_before='ifconfigeth0|sed-n"8"p|awk'{print$6}'|cut-c7-'sleep2speedrx_after='ifconfigeth0|sed-n"8"p|awk'{print$2}'|cut-c7-'speedtx_after='ifconfigeth0|sed-n"8"p|awk'{print$6}'|cut-c7-'echo"$speedday$speedtimeNow_In_Speed:"$speedrx_result"kbpsNow_OUt_Speed:Q:77.检测CPU#Inspect#SunJul3117:25:41CSTexportPATHexportCpuResult=$(top-bn1|grep"Cpu"|awk'{print$5}'|sedif[[$CpuResult<20echo"CPUWARNING:$CpuResult">/service/script/.cpu_in.txttop-bn1>>/service/script./cpu_in.txtmail-s"InspcetCPU"wl<#InsepctHarddisk,Iftheremainingspaceismorethan80%,themessageissenttothewl#TueAug209:45:56CSTexportforRemainingSpacein$(df-h|awk'{print$5}'|grep-v'Use'|sed-eif[[$RemainingSpace>80]];thenecho-e"$RemainingSpace"echo-e"$(df-h|grep$RemainingSpace)">/service/script/.HarddiskWarningmail-s"diskWarning"wl</service/script/.HarddiskWarningcurl-H'Content-Type:application/json'-{"text":{"content":}functions_row=`df|wc-l`foriin`seq2$s_row`temp=(`df-h|head-n$i|tail-n1|awk'{print$5"\t"$6}'`)disk="`echo${temp[0]}|cut-d"%"-f1`"IP=`ifconfig|grep-v""|grep"inetaddr:"|sed's/^.*inetaddr://g'|sed's/Bcas..*$//g'`#echo-e Dat=`date"+%Fif[$disk-ge$dftype]}
echo
========================主机名:$hostname\nIP地址:$IP\n分区名$namen使用率$diskn发生时间$Datn=========================HTTP_CODE=`curl-o/dev/null-s-w"%{http_code}"ifif[$HTTP_CODE!=200echo========================IP地址:$IP\n返回代码:$HTTP_CODE\发生时间$Dat=========================}desk_checkapache_checksleepQ:80.#InspectMemory:Ifthememoryislessthan500,thensendmailto#TueAug209:13:43CSTexport-m|grep"Mem"|awk'{printif[[MEM<500echo-e"MemoryWarning:$MEM">mail-s"MemoryWarning"wl<Q:81.剩余inode#InspcetInode:IftheINODEislessthan200,themessageissentto#TueAug210:21:29CSTexportInodein$(df-i|grep-v"Filesystem"|awk'{printif[[Inode<200echo-e"$(df-i|grepInode")"> mail-s InodeWarning"wl< declare-iwhileifwho|grep-q-E"^wang"echoe用户wang登陆了系统\n这是第$count次!letsleep~示例:找出UID为偶数的所有用户,显示其用户名和IDwhilereadline;userid=$(echo$line|cut-d:-f3)if[$[$userid%2]-eq0];thenecho$line|cut-d:-f1,3done<while[$sum-le30]if[$sum-le9]useraddecho"123456"|passwd--stdinchagechage-d0$userletsum=sum+1#nmapMAC=`catip|awk'$1=="MAC"&&$NF=="(VMware)"{printforiin`seq1IP=`cat/ip|grep-B5$temp|grep"Nmapscan"|awk'{print egrep"((25[0-5]|2[0-4][0-9]|((1[0-9]{2})|([1-9]?[0-9])))\.){3}(25[0-5]|2[0-4][0-ls|egrep"((25[0-5]|2[0-4][0-9]|((1[0-9]{2})|([1-9]?[0-9])))\.){3}(25[0-5]|2[0- |net|org|cn)$"ls|egrep"^(([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9]function{$1for((i=0;i<=$1;i++))for((s=0;s<=$2;s++))if[$[$i%2]==0]if[$[$s%2]==0]
echo-en"echo-en"\e[;44m
if[$[$s%2]==0
echo-en"\e[;42mecho-en"}ary_go25w|awk'NR>=3{printf$1"\t"$2"\t"$3"\n"}'>/tmp/who.txtforiin$(awk'{printf$1}'/tmp/bai.txt)k=$(egrep-v"$i"/tmp/who.txt|awk'{printf$2}"\n"'|awk'{printfforjin$kpkill-9-t61-88 ##CopyrightThetestscript2021Allrights color()SETCOLOR_SUCCESS="echo-en\\033[1;32m"SETCOLOR_FAILURE="echo-en\\033[1;31m"SETCOLOR_WARNING="echo-en\\033[1;33m"SETCOLOR_NORMAL="echo-en\E[0m"echo-n"$2"&&$MOVE_TO_COLecho-n"["if[$1="success"-o$1="0"]echo-n$"OKelif[$1="failure"-o$1="1"]echo-necho-necho-n"]"}os_typeawk-F'["]''/^NAME/{print$2}'/etc/os-}check()-e$db_dir-oe$install_dir/mongodb&&color1"MongoDB数据库已安装";exit;}if[`os_type`="CentOS"rpm-qcurl&>/dev/null||yuminstall-y-qcurlelif[`os_type`="Ubuntu"];thendpkg-lcurl&>/dev/null||apt-yinstall}
color1file_prepare()if[!-e$filecurl-O$url||{color1"MongoDB数据库文件失败";exit;}install_mongodb()tarxf$file-C$install_dirmkdir-p$db_dirln-s$install_dir/mongodb-linux-x86_64-*echoPATH=$install_dir/mongodb/bin/:'$PATH'>.$db_dir/mongod.log--$?-eq0&&color0"MongoDB数据库安装成功||color1"MongoDB数据库安装}xorg-x11-fonts-Type1firefox[root@centos 检测两台服务器指 下的文件致#通过对比两台服务器上文件的md5值,达到检测致性的目的 find$dir-typef|xargsmd5sum>ssh$b_ip"find$dir-typef|xargsmd5sum>/tmp/md5_b.txt"scp$b_ip:/tmp/md5_b.txt/tmp 比forfin`awk'{print2}ifgrep-qw"$f"/tmp/md5_b.txtmd5_a=`grepw$f"/tmp/md5_a.txt|awk'{print1}'`md5_b=`grepw$f"/tmp/md5_b.txt|awk'{print1}'`#当文件存在时,如果md5值不致则输出文件改变的结果if[$md5_a!=$md5_b]thenecho"$fchanged." logfile=/tmp/`date+%H-%F`.logn=`date+%H`if[$n-eq00]||[$n-eq12] foriin`find/data/log/-typef`foriin`find/data/log/-typef`du-sh$i>>$logfile#检测网卡流量,并按规定格式记录在日志中##2019-08-12#ens33input:1234bps#ens33output:whilelogfile=/tmp/`date exec>>$logfiledate+"%Fsar-nDEV159|grepAverage|grepens33|awkecho#使用awk只输出文档行数(截取第段)n=`wcla.txt|awkprint$1}'`#foriin`seq1n_n=`echo$line|seds'/[^0-9]//'g|wc-L`echo# psaux|grep指定进程名|grepvgrep|awk'{print$2}'|xargskillif[$#-ne1];echo"Usage:$0dir=$(dirname$1)ftpnv nopen0ftp服务器useradminpassword cd$dirwhile[$COUNT-le5];if$INT=~^[0-9]+$thenecho"输入必须是整数!"exitelif$INTgt100thenecho"输入必须是100以内!"exit1[$MIN-lt$INT]&&MIN=$INT[$MAX-gt$INT]&&MAX=$INTletCOUNT++echo"SUM:$SUM"echo"MIN:$MIN"echo"MAX:$MAX#!/bin/bash##!/bin/bash# 生成个100以内的随机数,提示用户猜数字,根据用户的输入,提示用户猜对了,#猜小了或猜大了,直至用户猜对 #RANDOM为系统自带的系统变量,值为0-32767#使用read提示用户猜数字#使用if判断用户猜数字的大小关系:-eq(等于),-ne(不等于),-gt(大于),-ge(大于等于),#-lt(小于),-le(小于等于)readp计算机生成了个1-100的随机数,你猜if[$cai-eq$numelif[$cai-gt$num]echo"Oops,猜大了echo"Oops,猜小了此需要编写,一旦出现502,则自动重启php-fpm服务。 死循环,每10秒检测 次,10秒的日志条数为300条,出现502的比例不低于10%(30条)则需要重#3.重启命令为:/etc/init.d/php-fpmrestart#监测 日志502情况,并做相应动N=30#设定阈值while err=`tail-n300$log|grep-c'502"'`if[$err-ge$N]/etc/init.d/php-fpmrestart2>/dev/null sleepforforiin$(echo"456");doevala$i=$idoneecho$a4$a5foriin$(evalecho$*);do letnum+=1echo$node1$node212方法3:arr=(456)INDEX3=$(echo##touch#lsarticle_1.htmlarticle_2.htmlforforfilein$(ls*html);domv$file#mv$file$(echo$file|sed-r's/.*(_.*)/bbs\1/')#mv$file$(echo$file|echobbs_$(cut-d_-f2)forforfilein$(find.-maxdepth1-name"*html");domv$filebbs_${file#*_}done##renamearticlebbs 第第2行 sed-n'1,5'p2.txt|sed'/[a-zA-sed-n'6,10'p2.txt|seds'/[a-zA-Z]//'gsed-n'11,$'p2.txt ##find.-name"*.html"-execdu-k{}\;|awk'{sum+=$1}END{print方法forsizein$(ls-l*.html|awk'{print$5}');doPORT="222580forPORTin$PORT;ifecho&>/dev/null>/dev/tcp/$HOST/$PORT;thenecho"$PORTopen"echo"$PORT用 #Bashalsointerpretsanumberofmulti-characteroptions. forsinBashalsointerpretsanumberofmulti-characteroptions.if[$n-lt6]echo"*cmd*1-date2-ls3-who4-pwd0-exit"while:read-p"pleaseinputnumber:"nn1=`echo$n|seds'/[0-9]//'g`if[-z"$n"]if[-n"$n1"]exit0case$ninecho"pleaseinputnumberis[1-4]"Q:103、Expect实现SSHexpect<<EOFsettimeout30spawnssh expect"(yes/no)""yes\r"; "password:"{send}expect"$USER@*"{send"$1\r"}expect"$USER@*"{send"exit\r"}expecteofexpect-cexpect{\"(yes/no)\"{send\"yes\r\";\"password:\"{send\"$PASS\r\";\"$USER@*\"{send\"df-h\rexit\r\"; #catlogin.expsetip[lindex$argv0]setuser[lindex$argv1]setpasswd[lindex$argv2]setcmd[lindex$argv3]if{$argc!=4}{puts"Usage:e
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2024版冷链仓储设备购买合同
- 虚拟办公竞争格局
- 解读用户行为分析与洞察
- 2024年度人工智能研发项目外包合同
- 高能量密度电池技术研究
- 04年企业资产并购合同
- 2024年度杯子原材料采购合同
- 2024年度光伏设备制造商购销合同
- 2024年度地产项目融资合作与宣传活动合同
- 2024年度云计算服务众包合同
- 王阳明心学课件
- 马克思主义基本原理概论(湖南师范大学)智慧树知到答案章节测试2023年
- 环境影响评价智慧树知到答案章节测试2023年桂林电子科技大学
- 2023年江苏小高考历史试卷含答案1
- 酒店事故风险评估报告
- 2022年全国统一高考日语真题试卷及答案
- GB/T 3280-2015不锈钢冷轧钢板和钢带
- GB/T 28655-2012业氟化氢铵
- 氧气(MSDS)安全技术说明书
- 第一章膳食调查与评价
- GB 5606.3-2005卷烟第3部分:包装、卷制技术要求及贮运
评论
0/150
提交评论