Precautions 1) Add interpreter at the beginning: #!/bin/bash 2) Use four spaces for syntax indentation and add more comments. 3) Naming suggestion rules: variable names are capitalized, local variables are lowercase, function names are lowercase, and the names should reflect their actual functions. 4) By default, variables are global. In a function, the variable local is specified as a local variable to avoid polluting other scopes. 5) There are two commands that can help me debug the script: set -e exits the script when a non-zero result is encountered, and set -x prints the execution process. 6) When writing a script, be sure to test it first before putting it into production. 1 Get a random string or number Get a random 8-bit string: Get a random 8-digit number: cksum: print CRC checksum statistics bytes 2 Define a color output string function The function keyword defines a function and can be added or not. 3. Create users in batches 4 Check if the package is installed 5 Check service status 6 Check host survival status Method 1: Put the wrong IP into an array to determine whether the ping fails three times Method 2: Put the number of errors into the FAIL_COUNT variable to determine whether the ping failed three times Method 3: Use the for loop to exit the loop if the ping succeeds. If it does not exit, it will print "ping failed" 7. Monitor CPU, memory and disk utilization 1) CPU Use the vmstat tool to analyze CPU statistics. 2) Memory 3) Hard disk 8 Batch host disk utilization monitoring Prerequisite: SSH non-interactive login or key login is used for the monitoring and monitored ends. Write a configuration file to save the SSH connection information of the monitored host. The file content format is: IP User Port 9. Check website availability 1) Check URL availability 2) Determine the availability of the URL three times The idea is the same as checking the host survival status above. Summarize The above is what I introduced to you about sharing 9 practical and commonly used Shell scripts for interviews. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website! You may also be interested in:
|
<<: WeChat Mini Program implements the likes service
>>: Detailed explanation of several ways to write private variables of ES6 implementation class
MongoDB is cross-platform and can be installed on...
Three MySQL instance processes are started on one...
Benefits of Prepare The reason why Prepare SQL is...
ant-design-vue customizes the use of Ali iconfont...
1. Background Netplan is a new command-line netwo...
Problem [root@zh ~]# [root@zh ~]# [root@zh ~]# yu...
Table of contents The cause of the incident Anato...
Tomcat CentOS Installation This installation tuto...
Keepalived+Nginx+Tomcat to achieve high availabil...
Example Usage Copy code The code is as follows: &l...
By default, MySQL can accept the insertion of 0 v...
Table of contents 1. Component bloat 2. Change th...
The author recently encountered a performance bot...
Automated build means using Docker Hub to connect...
Suggestion: Handwriting code as much as possible c...