Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Share 9 Linux Shell scripts commonly used in actual combat and interview

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Matters needing attention

1) add an interpreter at the beginning: #! / bin/bash

2) indent syntax, using four spaces; add more comments.

3) naming suggested rules: variable name uppercase, local variable lowercase, function name lowercase, name reflects the actual role.

4) the default variable is global, and the variable local is specified as a local variable in the function to avoid polluting other scopes.

5) there are two commands that can help me debug the script: set- e exits the script when it encounters non-zero execution, and set-x prints the execution process.

6) to write a script, be sure to test it before going to production.

1 get a random string or number

Get a random 8-bit string:

Get a random 8-digit number:

Cksum: print CRC validation and statistics bytes

2 define a color output string function

The function keyword defines a function that can be added or not.

3 create users in batch

4 check whether the software package is installed

5 check the service status

6 check the survival status of the host

Method 1: put the error IP in the array to determine whether the ping failed three times

Method 2: put the number of errors in the FAIL_COUNT variable to determine whether the ping failed three times

Method 3: use the for loop to jump out of the ping loop and continue. If you don't jump out, you will fail to print the ping.

7 Monitoring CPU, memory and hard disk utilization

1) CPU

Use the vmstat tool to analyze CPU statistics.

2) memory

3) hard disk

8 Monitoring of disk utilization of batch hosts

The premise is that the SSH of the monitoring side and the monitored side is free of interactive login or key login.

Write a configuration file to save the SSH connection information of the monitored host. The file format is IP User Port.

9 check website usability

1) check URL availability

2) determine the availability of URL three times

The idea is the same as above to check the survival status of the host.

Summary

The above is the editor to share 9 actual combat and interview commonly used Shell script writing, I hope to help you, if you have any questions, please leave me a message, the editor will reply to you in time. Thank you very much for your support to the website!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report