Some simple instances of shell scripting

Source: Internet
Author: User

1. Word Frequency statistics

Sed-e s/' [[:p UNCT:] '/'/g-e s/' [[:d igit:] '/'/g $filename | tr [A-z] [a-z] | Tr ' \ n ' | Tr ' \ n ' | Sed '/^$/d ' >>newfilename

#干掉文本中的标点和数字

#替换大小写

#替换换行符为空格后再替换空格为换行符 (may not be necessary)

#删除空行重定向到新文件

Sort newfilename| uniq-c | Sort-n

#排序后删除重复项并统计重复个数, and then reorder. The function of sort-n is to sort by numerical values.

The statistics section can also be used with awk: sed-e s/' [[:p UNCT:] '/'/g-e s/' [[:d igit:] '/'/g $filename | tr [A-z] [a-z] | Tr ' \ n ' ' |awk ' begin{rs= ""} {++w[$0]} end{for (A in W) if (a!= "") Print a ":" W[a]} ' |sort-k2-n

The output is similar.

2. Use ping to see the IP address of this network segment online.

For i in ' seq 2 255 '

Do

Ping-c 1 "192.168.1. $i" |grep "1 received" && echo "192.168.1. $i"

Done

3. Simple system Monitoring script

#!/bin/sh
CONTINUE () {

Read-p "Press ENTER to continue:"

}

Cpu_info () {

echo "Print the CPU info:"

Cat/proc/cpuinfo|awk ' begin{fs= ': "}/model name/{print" CPU Model: "$ $} ' |uniq

Cat/proc/cpuinfo|awk ' begin{fs= ': "}/CPU mhz/{print" cpu MHz: "$ $" MHz "} ' |uniq

}

Load_info () {

Echo

echo "Print the system load info:"

Uptime|awk ' begin{fs= ":"}{print $ |awk ' begin{fs= ","}{print "last 1 minute sys load:" $ "\nlast 5 minutes sys load" $ "\nl AST 15minutues sysload: "$" \ n "}"

}

Mem_info () {

Echo

echo "Print the system memory and swap info:"

Free-h |grep Mem|awk ' begin{fs= ""}{print "System free Memory Info:" $4 ""} '

Free-h |grep Swap|awk ' begin{fs= ""}{print "system Swap Info:" $4 ""} '

}

Disk_info () {

Echo

echo "Print the system disk info:"
Df-h

Echo

}

MAIN () {
Clear

echo "============================================"

echo "1.display the CPU info;"
echo "2.display the SYS load;"
echo "3.display MEM and swap info;"
echo "4.display the SYS disk info;"
echo "5.EXIT;"

echo "============================================"

Read-p "Please select an Iterm (1-5):" Select

CHOICE
}

CHOICE () {
Case $SELECT in
1)
Cpu_info
CONTINUE

MAIN

;;

2)
Load_info
CONTINUE
MAIN

;;

3)
Mem_info
CONTINUE
MAIN
;;

4)

Disk_info
CONTINUE
MAIN
;;

5)
Exit
;;

*)
CONTINUE
MAIN
;;
Esac

}

MAIN

Some simple instances of shell scripting

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.