Shell script for intelligent viewing

Source: Internet
Author: User

First, I did not write the script functions here. If you are interested, you can do it yourself. You have not written the shell script for a long time. If you write this script today, you should review it, I have been using python for a long time. However, in comparison, I am not competent. The following is a summary:


1 shell can only be used at the system level, and ptyhon can be used in any situation

2 shell is not as powerful as python, shell is dependent on the command, and python is powerful as a module

3. shell is recommended for management systems. python is required for O & M development.

4. The shell is easy to use and has rich python modules.

5 It is recommended that the system administrator must learn shell and then learn python, so learning python will be much faster.


The following is a shell script (very simple, Please bypass Daniel ):

[Root @ localhost ~] # Cat systeminfo. sh #! /Bin/bashwhiletruedoecho "#############################" echo "# enter the following option # "echo" # cpu (view CPU # "echo" # memory (view memory) # "echo" # process (number of system processes) # "echo" # disk (view hard disk usage) # "echo" # apache (view apache connection) # "echo" # tcp (view the top 10 IP addresses of connections) # "echo" # mysql (view the number of mysql connections) # "echo" # exit (exit) # "echo "###############################"#### ################################## echo "enter the information you want to view options: "read input ##################################### functioncpu () {top-n 1} functionmemory () {free-m} functionprocess () {ps-A | wc-l} functiondisk () {df-lh} functionapache () {netstat-n | awk '/^ tcp/{++ S [$ NF]}; END {for (a in S) print, S [a]} '} functiontcp () {netstat-anlp | grep 80 | grep tcp | awk' {print $5} '| awk-F: '{print $1}' | sort | uniq-c | sort-nr | head-n10} functionmysql () {netstat-anl | grep "3306" | wc-l} functionexit () {exit 0 }#################################### # case $ input incpu) cpu; memory) memory; process) process; disk) sidk; apache) apache; tcp) tcp; mysql) mysql; exit) exit ;;*) echo "enter normal options ";; esac ###################################### done

Explanation: The while endless loop is used to implement function Selection. function is used to define the function. Some children's shoes may say that writing directly in the judgment statement is not faster. It is recommended to program it here and differentiate it by function, in this way, you can easily modify the statements, and make the next system administrator or O & M personnel take over the statements.


Digress

At present, many enterprises seldom recruit system administrators, which are directly the O & M engineers, System Engineers, and O & M engineers. My personal views are as follows:


System Administrator: works at the system level, such as installing the system, maintaining the desktop, configuring the environment, installing the service, and then going online.


O & M Engineer: I feel like I have to understand everything. The system, network, programming, and system-level installation, optimization, and high availability are not much different from system administrators, you should often see the most important part when recruiting O & M engineers. Familiar with or proficient in shll | perl | python | php, shell is basically no difficulty for the present, in addition, O & M engineers in small companies also need "part-time" Database Administrators (db sa), and occasionally need to develop O & M tools.


Suggestions

Whether it is a system administrator or O & M engineer, you must learn shell + 3 P (one of them). I believe that advanced technology will certainly benefit you in the future.


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.