尊龙凯时人生就是博

ÔËά³£ÓÃµÄ 34 ¸ö Linux Shell ¾ç±¾£¬Ò»¶¨ÄÜ°ïµ½Ä㣡

×÷ΪһÃû Linux ¹¤³Ìʦ£¬»áдºÃµÄ¾ç±¾²»µ«ÄÜÌá¸ßÊÂÇéЧÂÊ£¬»¹ÄÜÓиü¶àµÄʱ¼ä×ö×Ô¼ºµÄÊ¡£×î½üÔÚÍøÉϳåÀ˵Äʱ¼ä£¬Ò²×¢ÖØÍøÂçһЩ´óÀÐд¹ýµÄ¾ç±¾£¬»ã×ÜÕûÀíһϣ¬½Ó´ýÕä²Ø£¬Óë¾ý¹²Ã㣡
£¨1£©Óû§²ÂÊý×Ö

#!/bin/bash# ¾ç±¾ÌìÉúÒ»¸ö 100 ÒÔÄÚµÄËæ»úÊý,ÌáÐÑÓû§²ÂÊý×Ö,ƾ֤Óû§µÄÊäÈë,ÌáÐÑÓû§²Â¶ÔÁË,# ²ÂСÁË»ò²Â´óÁË,Ö±ÖÁÓû§²Â¶Ô¾ç±¾¿¢Ê¡£# RANDOM Ϊϵͳ×Ô´øµÄϵͳ±äÁ¿,ֵΪ 0©\32767µÄËæ»úÊý# ʹÓÃÈ¡ÓàËã·¨½«Ëæ»úÊý±äΪ 1©\100 µÄËæ»úÊýnum=$[RANDOM%100+1]echo "$num"# ʹÓà read ÌáÐÑÓû§²ÂÊý×Ö# ʹÓà if ÅжÏÓû§²ÂÊý×ֵľÞϸ¹Øϵ:©\eq(¼´ÊÇ),©\ne(²»¼´ÊÇ),©\gt(´óÓÚ),©\ge(´óÓÚ¼´ÊÇ),# ©\lt(СÓÚ),©\le(СÓÚ¼´ÊÇ)while :do  read -p "ÅÌËã»úÌìÉúÁËÒ»¸ö 1©\100 µÄËæ»úÊý,Äã²Â: " cai      if [ $cai -eq $num ]       then             echo "¹§Ï²,²Â¶ÔÁË"             exit       elif [ $cai -gt $num ]       then                   echo "Oops,²Â´óÁË"           else                  echo "Oops,²ÂСÁË"   fidone

µÇ¼ºó¸´ÖÆ
£¨2£©Éó²éÓм¸¶àÔ¶³ÌµÄ IP ÔÚÅþÁ¬±¾»ú

#!/bin/bash#!/bin/bash# Éó²éÓм¸¶àÔ¶³ÌµÄ IP ÔÚÅþÁ¬±¾»ú(²»¹ÜÊÇͨ¹ý ssh ÕÕ¾É web ÕÕ¾É ftp ¶¼Í³¼Æ) # ʹÓà netstat ©\atn ¿ÉÒÔÉó²é±¾»úËùÓÐÅþÁ¬µÄ״̬,©\a Éó²éËùÓÐ,# -t½öÏÔʾ tcp ÅþÁ¬µÄÐÅÏ¢,©\n Êý×ÖÃûÌÃÏÔʾ# Local Address(µÚËÄÁÐÊDZ¾»úµÄ IP ºÍ¶Ë¿ÚÐÅÏ¢)# Foreign Address(µÚÎåÁÐÊÇÔ¶³ÌÖ÷»úµÄ IP ºÍ¶Ë¿ÚÐÅÏ¢)# ʹÓà awk ÏÂÁî½öÏÔʾµÚ 5 ÁÐÊý¾Ý,ÔÙÏÔʾµÚ 1 ÁÐ IP µØµãµÄÐÅÏ¢# sort ¿ÉÒÔ°´Êý×Ö¾ÞϸÅÅÐò,×îºóʹÓà uniq ½«¶àÓàÖظ´µÄɾ³ý,²¢Í³¼ÆÖظ´µÄ´ÎÊýnetstat -atn  |  awk  '{print $5}'  | awk  '{print $1}' | sort -nr  |  uniq -c

µÇ¼ºó¸´ÖÆ
(3£©helloworld

#!/bin/bashfunction example {echo "Hello world!"}example

µÇ¼ºó¸´ÖÆ
£¨4£©´òÓ¡ tomcat µÄpid

#!/bin/sh`v1="Hello"v2="world"v3=${v1}${v2}echo $v3pidlist=`ps -ef|grep apache-tomcat-7.0.75|grep -v "grep"|awk '{print $2}'`echo $pidlistecho "tomcat Id list :$pidlist"  //ÏÔʾpid

µÇ¼ºó¸´ÖÆ
£¨5£©¾ç±¾±àд ½Â¼ô ¡¢ ʯͷ¡¢²¼ÓÎÏ·

#!/bin/bashgame=(ʯͷ ½Â¼ô ²¼)num=$[RANDOM%3]computer=${game[$sum]}echo "Çëƾ֤ÏÂÁÐÌáÐÑÑ¡ÔñÄúµÄ³öÈ­ÊÖÊÆ"echo " 1. ʯͷ"echo " 2. ½Â¼ô"echo " 3. ²¼ "read -p "ÇëÑ¡Ôñ 1-3 £º" personcase $person in1)  if [ $num -eq 0 ]  then     echo "ƽÊÖ"    elif [ $num -eq 1 ]    then      echo "ÄãÓ®"    else       echo "ÅÌËã»úÓ®"fi;;2) if [ $num -eq 0 ] then    echo "ÅÌËã»úÓ®"    elif [ $num -eq 1 ]     then     echo "ƽÊÖ"    else       echo "ÄãÓ®"fi;;3) if [ $num -eq 0 ] then     echo "ÄãÓ®"   elif [ $num -eq 1 ]   then      echo "ÅÌËã»úÓ®"   else       echo "ƽÊÖ"fi;;*)  echo "±ØÐèÊäÈë1-3 µÄÊý×Ö"esac

µÇ¼ºó¸´ÖÆ
£¨6£©¾Å¾Å³Ë·¨±í

#!/bin/bashfor i in `seq 9`do  for j in `seq $i` do  echo -n "$j*$i=$[i*j] " done    echodone

µÇ¼ºó¸´ÖÆ
£¨7£©¾ç±¾ÓÃÔ´ÂëÀ´×°Öà memcached ЧÀÍÆ÷

#!/bin/bash# Ò»¼ü°²ÅÅ memcached # ¾ç±¾ÓÃÔ´ÂëÀ´×°Öà memcached ЧÀÍÆ÷# ×¢ÖØ:ÈôÊÇÈí¼þµÄÏÂÔØÁ´½ÓÓâÆÚÁË,Çë¸üРmemcached µÄÏÂÔØÁ´½Ówget http://www.memcached.org/files/memcached-1.5.1.tar.gzyum -y install gcctar -xf  memcached©\1.5.1.tar.gzcd memcached©\1.5.1./configuremakemake install

µÇ¼ºó¸´ÖÆ
£¨8£©¼ì²â±¾»úÄ¿½ñÓû§ÊÇ·ñΪ³¬µÈÖÎÀíÔ±¡£ÁíÍ⣬ËÑË÷ÃñÖںűà³ÌÊÖÒÕȦºǫ́»Ø¸´¡°´óÀñ°ü¡±£¬»ñÈ¡Ò»·Ý¾ªÏ²Àñ°ü¡£

#!/bin/bash# ¼ì²â±¾»úÄ¿½ñÓû§ÊÇ·ñΪ³¬µÈÖÎÀíÔ±,ÈôÊÇÊÇÖÎÀíÔ±,ÔòʹÓà yum ×°Öà vsftpd,ÈôÊDz»# ÊÇ,ÔòÌáÐÑÄú·ÇÖÎÀíÔ±(ʹÓÃ×Ö´®±ÈÕÕ°æ±¾) if [ $USER == "root" ] then  yum -y install vsftpdelse  echo "Äú²»ÊÇÖÎÀíÔ±£¬Ã»ÓÐȨÏÞ×°ÖÃÈí¼þ"fi

µÇ¼ºó¸´ÖÆ
£¨9£©if ÔËËã±í´ïʽ

#!/bin/bash -xvif [ $1 -eq 2 ] ;then echo "wo ai wenmin"elif [ $1 -eq 3 ] ;then  echo "wo ai wenxing "elif [ $1 -eq 4 ] ;then  echo "wo de xin "elif [ $1 -eq 5 ] ;then echo "wo de ai "fi

µÇ¼ºó¸´ÖÆ
£¨10£©¾ç±¾ ɱµô tomcat Àú³Ì²¢ÖØÐÂÆô¶¯

#!/bin/bash#kill tomcat pidpidlist=`ps -ef|grep apache-tomcat-7.0.75|grep -v "grep"|awk '{print $2}'`  #ÕÒµ½tomcatµÄPIDºÅecho "tomcat Id list :$pidlist"  //ÏÔʾpidkill -9 $pidlist  #ɱµôˢгÌecho "KILL $pidlist:" //ÌáÐÑÀú³ÌÒÔ¼°±»É±µôecho "service stop success"echo "start tomcat"cd /opt/apache-tomcat-7.0.75pwd rm -rf work/*cd bin./startup.sh #;tail -f ../logs/catalina.out

µÇ¼ºó¸´ÖÆ
£¨11£©´òÓ¡¹ú¼ÊÏóÆåÆåÅÌ

#!/bin/bash# ´òÓ¡¹ú¼ÊÏóÆåÆåÅÌ# ÉèÖÃÁ½¸ö±äÁ¿,i ºÍ j,Ò»¸ö´ú±íÐÐ,Ò»¸ö´ú±íÁÐ,¹ú¼ÊÏóÆåΪ 8*8 ÆåÅÌ# i=1 ÊÇ´ú±í×¼±¸´òÓ¡µÚÒ»ÐÐÆåÅÌ,µÚ 1 ÐÐÆåÅÌÓлÒÉ«ºÍÀ¶É«¾àÀëÊä³ö,×ܹ²Îª 8 ÁÐ# i=1,j=1 ´ú±íµÚ 1 ÐÐµÄµÚ 1 ÁÐ;i=2,j=3 ´ú±íµÚ 2 ÐÐµÄµÚ 3 ÁÐ# ÆåÅ̵ļÍÂÉÊÇ i+j ÈôÊÇÊÇżÊý,¾Í´òÓ¡À¶É«É«¿é,ÈôÊÇÊÇÆæÊý¾Í´òÓ¡»ÒÉ«É«¿é# ʹÓà echo ©\ne ´òÓ¡É«¿é,²¢ÇÒ´òÓ¡Íê³ÉÉ«¿éºó²»×Ô¶¯»»ÐÐ,ÔÚͳһÐмÌÐøÊä³öÆäËûÉ«¿éfor i in {1..8}do   for j in {1..8}   do    sum=$[i+j]  if [  $[sum%2] -eq 0 ];then    echo -ne "\033[46m  \033[0m"  else   echo -ne "\033[47m  \033[0m"  fi   done   echodone

µÇ¼ºó¸´ÖÆ
£¨12£©Í³¼ÆÄ¿½ñ Linux ϵͳÖпÉÒԵǼÅÌËã»úµÄÕË»§Óм¸¶à¸ö

#!/bin/bash# ͳ¼ÆÄ¿½ñ Linux ϵͳÖпÉÒԵǼÅÌËã»úµÄÕË»§Óм¸¶à¸ö#ÒªÁì 1:grep "bash$" /etc/passwd | wc -l#ÒªÁì 2£ºawk -f : '/bash$/{x++}end{print x}' /etc/passwd

µÇ¼ºó¸´ÖÆ
£¨13£©±¸·Ý MySQL ±íÊý¾Ý

#!/bin/shsource /etc/profiledbName=mysqltableName=dbecho [`date +'%Y-%m-%d %H:%M:%S'`]' start loading data...'mysql -uroot -proot -P3306 ${dbName} -e "LOAD DATA LOCAL INFILE '# /home/wenmin/wenxing.txt' INTO TABLE ${tableName} FIELDS TERMINATED BY ';'"echo [`date +'%Y-%m-%d %H:%M:%S'`]' end loading data...'exitEOF

µÇ¼ºó¸´ÖÆ
£¨14£©Ê¹ÓÃËÀÑ­»·ÊµÊ±ÏÔʾ eth0 Íø¿¨·¢Ë͵ÄÊý¾Ý°üÁ÷Á¿

#!/bin/bash# ʹÓÃËÀÑ­»·ÊµÊ±ÏÔʾ eth0 Íø¿¨·¢Ë͵ÄÊý¾Ý°üÁ÷Á¿ while :do  echo 'ÍâµØÍø¿¨ ens33 Á÷Á¿ÐÅÏ¢ÈçÏ£º' ifconfig ens33 | grep "RX pack" | awk '{print $5}'     ifconfig ens33 | grep "TX pack" | awk '{print $5}' sleep 1done

µÇ¼ºó¸´ÖÆ
£¨15£©±àд¾ç±¾²âÊÔ 192.168.4.0/24 Õû¸öÍø¶ÎÖÐÄÄЩÖ÷»ú´¦ÓÚ¿ª»ú״̬£¬ÄÄЩÖ÷»ú´¦Óڹػú

#!/bin/bash# ±àд¾ç±¾²âÊÔ 192.168.4.0/24 Õû¸öÍø¶ÎÖÐÄÄЩÖ÷»ú´¦ÓÚ¿ª»ú״̬,ÄÄЩÖ÷»ú´¦Óڹػú# ״̬(for °æ±¾)for i in {1..254}do  # ÿ¸ô0.3ÃëpingÒ»´Î£¬Ò»¹²ping2´Î£¬²¢ÒÔ1ºÁÃëΪµ¥Î»ÉèÖÃpingµÄ³¬Ê±Ê±¼ä ping -c 2 -i 0.3 -W 1 192.168.1.$i &>/dev/null     if [ $? -eq 0 ];then echo "192.168.1.$i is up" else  echo "192.168.1.$i is down" fidone

µÇ¼ºó¸´ÖÆ
£¨16£©±àд¾ç±¾£ºÌáÐÑÓû§ÊäÈëÓû§ÃûºÍÃÜÂë,¾ç±¾×Ô¶¯½¨ÉèÏìÓ¦µÄÕË»§¼°ÉèÖÃÃÜÂë¡£ÈôÊÇÓû§¡£ÁíÍ⣬ËÑË÷ÃñÖÚºÅLinux¾Í¸ÃÕâÑùѧºǫ́»Ø¸´¡°Linux¡±£¬»ñÈ¡Ò»·Ý¾ªÏ²Àñ°ü¡£

#!/bin/bash# ±àд¾ç±¾:ÌáÐÑÓû§ÊäÈëÓû§ÃûºÍÃÜÂë,¾ç±¾×Ô¶¯½¨ÉèÏìÓ¦µÄÕË»§¼°ÉèÖÃÃÜÂë¡£ÈôÊÇÓû§# ²»ÊäÈëÕË»§Ãû,ÔòÌáÐѱØÐèÊäÈëÕË»§Ãû²¢Í˳ö¾ç±¾;ÈôÊÇÓû§²»ÊäÈëÃÜÂë,ÔòͳһʹÓÃĬ# È쵀 123456 ×÷ΪĬÈÏÃÜÂë¡£read -p "ÇëÊäÈëÓû§Ãû£º" user#ʹÓé\z ¿ÉÒÔÅжÏÒ»¸ö±äÁ¿ÊÇ·ñΪ¿Õ,ÈôÊÇΪ¿Õ,ÌáÐÑÓû§±ØÐèÊäÈëÕË»§Ãû,²¢Í˳ö¾ç±¾,Í˳öÂëΪ 2#ûÓÐÊäÈëÓû§Ãû¾ç±¾Í˳öºó,ʹÓÃ$?Éó²éµÄ·µ»ØÂëΪ 2if [ -z $user ]; then echo " Äú²»ÐèÒªÊäÈëÕË»§Ãû"  exit 2fi #ʹÓà stty ©\echo ¹Ø±Õ shell µÄ»ØÏÔ¹¦Ð§#ʹÓà stty  echo ·­¿ª shell µÄ»ØÏÔ¹¦Ð§stty -echo read -p "ÇëÊäÈëÃÜÂ룺" passstty echo pass=${pass:-123456}useradd "$user"echo "$pass" | passwd --stdin "$user"

µÇ¼ºó¸´ÖÆ
£¨17£©Ê¹Óþ籾¶ÔÊäÈëµÄÈý¸öÕûÊý¾ÙÐÐÅÅÐò

#!/bin/bash# ÒÀ´ÎÌáÐÑÓû§ÊäÈë 3 ¸öÕûÊý,¾ç±¾Æ¾Ö¤Êý×Ö¾ÞϸÒÀ´ÎÅÅÐòÊä³ö 3 ¸öÊý×Öread -p " ÇëÊäÈëÒ»¸öÕûÊý£º" num1read -p " ÇëÊäÈëÒ»¸öÕûÊý£º" num2read -p " ÇëÊäÈëÒ»¸öÕûÊý:  " num3# ²»¹ÜË­´ó˭С,×îºó¶¼´òÓ¡ echo "$num1,$num2,$num3"# num1 ÖÐÓÀÔ¶´æ×îСµÄÖµ,num2 ÖÐÓÀÔ¶´æÖÐÐÄÖµ,num3 ÓÀÔ¶´æ×î´óÖµ# ÈôÊÇÊäÈëµÄ²»ÊÇÕâÑùµÄ˳Ðò,Ôò¸Ä±äÊýµÄ´æ´¢Ë³Ðò,Èç:¿ÉÒÔ½« num1 ºÍ num2 µÄÖµ¶Ôµ÷tmp=0# ÈôÊÇ num1 ´óÓÚ num2,¾Í°Ñ num1 ºÍºÍ num2 µÄÖµ¶Ôµ÷,È·±£ num1 ±äÁ¿ÖдæµÄÊÇ×îСֵif [ $num1 -gt $num2 ];then tmp=$num1 num1=$num2 num2=tmpfi# ÈôÊÇ num1 ´óÓÚ num3,¾Í°Ñ num1 ºÍ num3 ¶Ôµ÷,È·±£ num1 ±äÁ¿ÖдæµÄÊÇ×îСֵif [ $num1 -gt $num3 ];then tmp=$num1 num1=$num3 num3=$tmpfi# ÈôÊÇ num2 ´óÓÚ num3,¾Í°Ñ num2 ºÍ num3 ¶Ôµ÷,È·±£ num2 ±äÁ¿ÖдæµÄÊÇ×îСֵif [ $num2 -gt $num3 ];then tmp=$num2 num2=$num3 num3=$tmpfiecho "ÅÅÐòºóÊý¾Ý£¨´ÓСµ½´ó£©Îª£º$num1,$num2,$num3"

µÇ¼ºó¸´ÖÆ
£¨18£©Æ¾Ö¤ÅÌËã»úÄ¿½ñʱ¼ä£¬·µ»ØÎʺòÓ¿ÉÒÔ½«¸Ã¾ç±¾ÉèÖÃΪ¿ª»úÆô¶¯

#!/bin/bash# ƾ֤ÅÌËã»úÄ¿½ñʱ¼ä,·µ»ØÎʺòÓï,¿ÉÒÔ½«¸Ã¾ç±¾ÉèÖÃΪ¿ª»úÆô¶¯ # 00©\12 µãΪÔ糿,12©\18 µãΪÏÂÕ½Êé,18©\24 µãΪÍíÉÏ# ʹÓà date ÏÂÁî»ñȡʱ¼äºó,if ÅжÏʱ¼äµÄÇø¼ä,È·¶¨ÎʺòÓïÄÚÈÝtm=$(date +%H)if [ $tm -le 12 ];then msg="Good Morning $USER"elif [ $tm -gt 12 -a $tm -le 18 ];then   msg="Good Afternoon $USER"else   msg="Good Night $USER"fiecho "Ä¿½ñʱ¼äÊÇ:$(date +"%Y©\%m©\%d %H:%M:%S")"echo -e "\033[34m$msg\033[0m"

µÇ¼ºó¸´ÖÆ
£¨19£©½« I lov cls дÈëµ½ txt ÎļþÖÐ

#!/bin/bashcd /home/wenmin/touch wenxing.txtecho "I lov cls" >>wenxing.txt

µÇ¼ºó¸´ÖÆ
£¨20£©¾ç±¾±àд for Ñ­»·ÅжÏ

#!/bin/bashs=0;for((i=1;i<100;i++))do  s=$[$s+$i]done echo $sr=0;a=0;b=0;for((x=1;x<9;x++))do  a=$[$a+$x] echo $xdonefor((y=1;y<9;y++))do  b=$[$b+$y]echo $ydoneecho $r=$[$a+$b]

µÇ¼ºó¸´ÖÆ
£¨21£©¾ç±¾±àд for Ñ­»·ÅжÏ

#!/bin/bashfor i in "$*"do  echo "wenmin xihuan $i"donefor j in "$@"do  echo "wenmin xihuan $j"done

µÇ¼ºó¸´ÖÆ
£¨22£©¾ç±¾ ÿÖÜ 5 ʹÓà tar ÏÂÁ·Ý/var/log ϵÄËùÓÐÈÕÖ¾Îļþ

#!/bin/bash# ÿÖÜ 5 ʹÓà tar ÏÂÁ·Ý/var/log ϵÄËùÓÐÈÕÖ¾Îļþ# vim  /root/logbak.sh# ±àд±¸·Ý¾ç±¾,±¸·ÝºóµÄÎļþÃû°üÀ¨ÈÕÆÚ±êÇ©,±ÜÃâºóÃæµÄ±¸·Ý½«Ç°ÃæµÄ±¸·ÝÊý¾ÝÁýÕÖ# ×¢ÖØ date ÏÂÁîÐèҪʹÓ÷´ÒýºÅÀ¨ÆðÀ´,·´ÒýºÅÔÚ¼üÅÌ<tab>¼üÉÏÃætar -czf log-`date +%Y%m%d`.tar.gz /var/log # crontab -e #±àдÍýÏëʹÃü£¬Ö´Ðб¸·Ý¾ç±¾00 03 * * 5 /home/wenmin/datas/logbak.sh

µÇ¼ºó¸´ÖÆ
£¨23£©¾ç±¾±àд ÇóºÍ º¯ÊýÔËËã function xx()

Å£±Æ°¡£¡½Ó˽»î±Ø±¸µÄ N ¸ö¿ªÔ´ÏîÄ¿£¡¸ÏæÕä²Ø

µÇ¼ºó¸´ÖÆ

#!/bin/bash

function sum()
{
 s=0;
 s=$[$1+$2]
 echo $s
}
read -p "input your parameter " p1
read -p "input your parameter " p2

sum $p1 $p2

function multi()
{
 r=0;
 r=$[$1/$2]
 echo $r
}
read -p "input your parameter " x1
read -p "input your parameter " x2

multi $x1 $x2

v1=1
v2=2
let v3=$v1+$v2
echo $v3

µÇ¼ºó¸´ÖÆ
£¨24£©¾ç±¾±àд case ¡ª esac ·ÖÖ§½á¹¹±í´ïʽ

#!/bin/bash 

case $1 in 
1) 
 echo "wenmin "
;;
2)
 echo "wenxing "
;; 
3)  
 echo "wemchang "
;;
4) 
 echo "yijun"
;;
5)
 echo "sinian"
;;
6)  
 echo "sikeng"
;;
7) 
 echo "yanna"
;;
*)
 echo "danlian"
;; 
esac

µÇ¼ºó¸´ÖÆ
£¨25£©# ½ç˵Ҫ¼à¿ØµÄÒ³ÃæµØµã£¬¶Ô tomcat ״̬¾ÙÐÐÖØÆô»òά»¤

#!/bin/sh  
# function:×Ô¶¯¼à¿ØtomcatÀú³Ì£¬¹ÒÁ˾ÍÖ´ÐÐÖØÆô²Ù×÷  
# author:huanghong  
# DEFINE  

# »ñÈ¡tomcat PPID  
TomcatID=$(ps -ef |grep tomcat |grep -w 'apache-tomcat-7.0.75'|grep -v 'grep'|awk '{print $2}')  

# tomcat_startup  
StartTomcat=/opt/apache-tomcat-7.0.75/bin/startup.sh  


#TomcatCache=/usr/apache-tomcat-5.5.23/work  

# ½ç˵Ҫ¼à¿ØµÄÒ³ÃæµØµã  
WebUrl=http://192.168.254.118:8080/

# ÈÕÖ¾Êä³ö  
GetPageInfo=/dev/null  
TomcatMonitorLog=/tmp/TomcatMonitor.log  

Monitor()  
  {  
   echo "[info]×îÏȼà¿Øtomcat...[$(date +'%F %H:%M:%S')]"  
   if [ $TomcatID ]
 then  
      echo "[info]tomcatÀú³ÌIDΪ:$TomcatID."  
      # »ñÈ¡·µ»Ø״̬Âë  
      TomcatServiceCode=$(curl -s -o $GetPageInfo -m 10 --connect-timeout 10 $WebUrl -w %{http_code})  
      if [ $TomcatServiceCode -eq 200 ];then  
          echo "[info]·µ»ØÂëΪ$TomcatServiceCode,tomcatÆô¶¯ÀÖ³É,Ò³ÃæÕý³£."  
      else  
          echo "[error]»á¼ûÍÉ»¯£¬×´Ì¬ÂëΪ$TomcatServiceCode,¹ýʧÈÕÖ¾ÒÑÊä³öµ½$GetPageInfo"  
          echo "[error]×îÏÈÖØÆôtomcat"  
          kill -9 $TomcatID  # ɱµôÔ­tomcatÀú³Ì  
          sleep 3  
          #rm -rf $TomcatCache # ÕûÀítomcat»º´æ  
          $StartTomcat  
      fi  
      else  
      echo "[error]Àú³Ì²»±£´æ!tomcat×Ô¶¯ÖØÆô..."  
      echo "[info]$StartTomcat,ÇëÉÔºò......"  
      #rm -rf $TomcatCache  
      $StartTomcat  
    fi  
    echo "------------------------------"  
   }  
   Monitor>>$TomcatMonitorLog

µÇ¼ºó¸´ÖÆ
£¨26£©Í¨¹ýλÖñäÁ¿½¨Éè Linux ϵͳÕË»§¼°ÃÜÂë

#!/bin/bash

# ͨ¹ýλÖñäÁ¿½¨ÉèLinux ϵͳÕË»§¼°ÃÜÂë

# $1 ÊÇÖ´Ðо籾µÄµÚÒ»¸ö²ÎÊý£¬$2  ÊÇÖ´Ðо籾µÄµÚ¶þ¸ö²ÎÊý

useradd "$1"
echo "$2" | passwd --stdin "$1"

µÇ¼ºó¸´ÖÆ
£¨27£©¶Ô±äÁ¿µÄ´«ÈëÓë»ñÈ¡¸öÊý¼°´òÓ¡

#!/bin/bash
echo "$0 $1 $2 $3"  // ´«ÈëÈý¸ö²ÎÊý
echo $#    //»ñÈ¡´«Èë²ÎÊýµÄÊýÄ¿
echo $@    //´òÓ¡»ñÈ¡´«Èë²ÎÊý
echo $*    //´òÓ¡»ñÈ¡´«Èë²ÎÊý

µÇ¼ºó¸´ÖÆ
£¨28£©ÊµÊ±¼à¿Ø±¾»úÄÚ´æºÍÓ²ÅÌÊ£Óà¿Õ¼ä£¬Ê£ÓàÄÚ´æСÓÚ500M¡¢¸ù·ÖÇøÊ£Óà¿Õ¼äСÓÚ1000Mʱ£¬·¢Ëͱ¨¾¯Óʼþ¸ørootÖÎÀíÔ±

#!/bin/bash

# ʵʱ¼à¿Ø±¾»úÄÚ´æºÍÓ²ÅÌÊ£Óà¿Õ¼ä,Ê£ÓàÄÚ´æСÓÚ500M¡¢¸ù·ÖÇøÊ£Óà¿Õ¼äСÓÚ1000Mʱ,·¢Ëͱ¨¾¯Óʼþ¸ørootÖÎÀíÔ±

# ÌáÈ¡¸ù·ÖÇøÊ£Óà¿Õ¼ä
disk_size=$(df / | awk '/\//{print $4}')

# ÌáÈ¡ÄÚ´æÊ£Óà¿Õ¿Õ¼ä
mem_size=$(free | awk '/Mem/{print $4}')
while :
do 
# ×¢ÖØÄÚ´æºÍ´ÅÅÌÌáÈ¡µÄ¿Õ¼ä¾Þϸ¶¼ÊÇÒÔ Kb Ϊµ¥Î»
if  [  $disk_size -le 512000 -a $mem_size -le 1024000  ]
then
    mail  ©\s  "Warning"  root  <<EOF
 Insufficient resources,×ÊԴȱ·¦
EOF
fi
done

µÇ¼ºó¸´ÖÆ
£¨29£©¼ì²éÖ¸¶¨Ä¿Â¼ÏÂÊÇ·ñ±£´æ ¶ÔÓ¦ Îļþ

#!/bin/bash

if [ -f /home/wenmin/datas ]
then 
echo "File exists"
fi

µÇ¼ºó¸´ÖÆ
£¨30£©¾ç±¾½ç˵whileÑ­»·Óï¾ä

#!/bin/bash

if [ -f /home/wenmin/datas ]
then 
echo "File exists"
fi

[root@rich datas]# cat while.sh 
#!/bin/bash

s=0
i=1
while [ $i -le 100 ]
do
        s=$[$s + $i]
        i=$[$i + 1]
done

echo $s
echo $i

µÇ¼ºó¸´ÖÆ
£¨31£©Ò»¼ü°²ÅÅ LNMP£¨RPM °ü°æ±¾£©

#!/bin/bash 

# Ò»¼ü°²ÅÅ LNMP(RPM °ü°æ±¾)
# ʹÓà yum ×°Öð²ÅÅ LNMP,ÐèÒªÌáÇ°ÉèÖúà yum Ô´,²»È»¸Ã¾ç±¾»áʧ°Ü
# ±¾¾ç±¾Ê¹ÓÃÓÚ centos7.2 »ò RHEL7.2
yum -y install httpd
yum -y install mariadb mariadb-devel mariadb-server
yum -y install php php-mysql

systemctl start httpd mariadb
systemctl enable httpd mariadb

µÇ¼ºó¸´ÖÆ
£¨32£©¶ÁÈ¡¿ØÖÆ̨´«Èë²ÎÊý

#!/bin/bash
read -t 7 -p "input your name " NAME
echo $NAME

read -t 11 -p "input you age " AGE
echo $AGE

read -t 15 -p "input your friend " FRIEND
echo $FRIEND

read -t 16 -p "input your love " LOVE
echo $LOVE

µÇ¼ºó¸´ÖÆ
£¨33£©¾ç±¾ÊµÏÖ ¸´ÖÆ

#!/bin/bash

cp $1 $2

µÇ¼ºó¸´ÖÆ
£¨34£©¾ç±¾ÊµÏÖÎļþ±£´æÓë·ñµÄÅжÏ

#!/bin/bash

if [ -f file.txt ];then
 echo "Îļþ±£´æ"
else 
 echo "Îļþ²»±£´æ"
fi

µÇ¼ºó¸´ÖÆ

ÒÔÉϾÍÊÇÔËά³£ÓÃµÄ 34 ¸ö Linux Shell ¾ç±¾£¬Ò»¶¨ÄÜ°ïµ½Ä㣡µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí£¬°æȨÕùÒéÓë±¾Õ¾Î޹أ¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í尊龙凯时人生就是博ÂËÓÍ»úÍø¹Ù·½Ì¬¶È£¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ£¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢£¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢£¬ÇëÄúÁ¬Ã¦ÁªÏµ尊龙凯时人生就是博ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ尊龙凯时人生就是博

13452372176

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎ壬9:30-18:30£¬½ÚãåÈÕÐÝÏ¢

QR code
sitemap¡¢ÍøÕ¾µØͼ