Shell Enterprise-Class Utility Foundation script (Rollup 2/2)

Source: Internet
Author: User
Tags rsync

Enterprise Utility Script 16

Enterprise Case: Write Network Service standalone process mode rsync system startup script

For example:/etc/init.d/rsyncd{start|stop|restart}.

Requirements:

1. To use the System function library technique.

2. To use a function, not a lump of Shi's way.

3. Can be managed by chkconfig

#!/bin/bash[ -f /etc/init.d/functions ]&& . /etc/init.d/functions| | Exit 2start () {      if [  ' lsof -i:873|wc -l '  -gt  0 ];then         echo  "rsync is running ... "      else         rsync - -daemon         [  ' Lsof -i:873|wc -l '  -gt  0 ]&&action  "Rsync start ..."  /bin/true      fi       return  $RETVAL}stop () {      if [   ' Lsof -i:873|wc -l '  -eq 0 ];then          echo  "Rsync is not running ..."       else          killall rsync         sleep 3          [  ' Lsof -i:873|wc -l '  -eq 0 ]& &action  "Rsync stop ..."  /bin/true      fi       return  $RETVAL}main () {   case  "$"  in       start|start)                    Start                   ;;       stop| STOP)                    Stop                   ;;       restart| RESTART)                    stop                   sleep 2                   Start                   ;;       *)                    echo -e  "Usage:$0 {start|stop|restart}"                    exit 1    esac     }main $1exit  $RETVAL

Enterprise Utility Script 17

1, after the execution of the script, enter the user's English name all spell, produce a random number 01-99 between the number, the number that has appeared before the next time can not appear

2, the first input name, the screen output information, and the name and number recorded in the file, the program can not exit continue to wait for input.

#!/bin/bashname () {   while true   do   read -p  " Input you name: " a   [ ! -z " $a " ]&&break    done}check_num () {      exec < random_num.txt       while read line      do          a= ' echo  $line |awk  ' {print $2} '           [  "$num"  =  "$A"  ]&&result=1&&break       done      result=0}random_num () {       for ((i=1;i<5;i++))       do         name        num= ' echo  $RANDOM |cut -c  1-2 '         [  ' cat random_num.txt|grep  $num |wc -l '  -gt 0 ]& &result=1| | result=0         #check_num           #echo   $result         [  $result  -eq 1 ] &&continue        echo  "you name is  $a, num  is  $num, done. "         echo  $a   $num  >> random_num.txt       done}main () {      echo  "Name num"   > random_num.txt      random_num}main

Enterprise Utility Script 18

The following string is known to be the result of the random number variable md5sum|cut-c 1-8 intercept, please crack these strings corresponding to the md5sum before the random corresponding number?

21029299

00205d1c

a3da1677

1f6d12dd

cf6a5205

#!/bin/sharray= (      21029299      00205d1c       a3da1677      1f6d12dd       cf6a5205) for ((m=1;m<100000;m++))    do      a= ' echo   $m |md5sum|cut -c 1-8 '       for ((n=0;n<${#array [@]};n++)]           do              if [  "$A"  =  "${array[$n]}"  ];then                 echo  "$m  = ${ array[$n]} "                 echo  "$m  = ${array[$n]}" >>crack.txt              else                continue              fi           done      [ $ (($m%100))  -eq 0 ]& &echo  "$m ... done"    doneecho  "All done."

Enterprise Utility Script 19

Batch check multiple Web site addresses are normal

Requirements: Shell array method Implementation, detection strategy as far as possible to simulate user access ideas

http://www.etiantian.org

Http://www.taobao.com

Http://oldboy.blog.51cto.com

http://10.0.0.7

#!/bin/sharray= (     http://www.etiantian.org     https:// www.taobao.com     http://oldboy.blog.51cto.com     http:// 10.0.0.7     http://www.lichengbing.com     http:// www.lichengbing.cn) for ((i=0;i<${#array [@]};i++))    do    status= ' Curl  -I -s -o /dev/null -w  "%{http_code}\n"  ${array[$i]} '      if [  $status  -eq 200 -o  $status  -eq 301 ];then        echo  "${array[$i]} ok"     else        echo  "${array[$i]} no"     fi   done

Enterprise Utility Script 20

1, according to the frequency of word occurrence descending sort!

2, in descending order by the frequency of letters!

The Squid project provides a number of resources toassist users design,implement and support squid installations. Browsethe documentation and support sections for more infomation

#!/bin/shword= "the squid project provides a number of resources  Toassist users design,implement and support squid installations. please  browsethe documentation and support sections for more infomation "#A = ' echo  $word |egrep -o  ' [a-za-z]+ ' |sort|uniq -c|sort -r ' #A = ' echo  $word |sed  ' s# [,.] # #g ' |tr  '   '   ' \ |sort|uniq -c|sort -r ' #A = ' echo  $word |sed  ' s#[,. ]#\n#g ' |grep -v  ' ^$ "|awk  ' {array[$1]++}end{for (Key in array) Print key,array[key]} ' | Sort -k2rn ' a= ' echo  $word |awk  ' begin{rs= ""}{for (i=1;i<=nf;i++) if ($i  !~ /[ ,.] /) count[$i]++}end{for (key in count) Print key,count[key]} ' |sort -k2rn ' B= ' echo  $word |tr   "[,.  ]"   " " |sed  ' s# # #g ' |grep -o  "\w" |sort|uniq -c|sort -rn ' b= ' echo  $word |tr  "[,.  ]"   " " |sed  ' s# # #g ' |sed -r  ' s# (.) #\1\n#g ' |sort -r|uniq -c|sort -rn ' echo  $Aecho   $B

Enterprise Utility Script 21

Please write a square with a shell or Python to receive the user input number

#!/bin/shread -p  "Input a number:"  numfor  ((i=1;i<= $num; i++))   do       for ((m=1;m<=$ ($num)) (m++))           do            printf  "*"           done  printf  "\ n"   done[[email  protected] shell]# sh shell_21.sh input a number:5****************************** #!/bin/shread -p  "Input a number:"  numfor  ((i=1;i<= $num; i++)    do      for ((m=1;m<= $num; m++))           do            printf  ""          done  printf  "\ n"   done[[email  protected] sheLl]# sh shell_21_02.sh input a number:6 #!/bin/ shread -p  "Input a num:"  numfor ((i=1;i<= $num; i++))    do        for (n= $num;n> $i; n--))                do                  printf  " "                done       for (((m=1;m<= $i-1); m++))           do         printf  "*"          done   printf  "\ n"     done[[email protected] shell]# sh shell_21_03.sh Input a num:7       *     ***    *****   *******  *  ************************

Shell Enterprise-Class Utility Foundation script (Rollup 2/2)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.