Day Three: Conditional selection
Outline
application Example Analysis
Condition test
if...else...fi
Case...in...esac
Implement function Menu :
After executing the script
Press 1 to display the current time
Press 2 to show CPU load
Variable
Get the native host name
#hostname
Get the system version number
#uname-R
Get CPU Type
Get the CPU working frequency
Cat/proc/cpuinfo
Get Memory
First, compression and decompression
1, compress [-RCV] file or directory
uncompress files. Z
-R: Can be compressed together with the files in the directory
-C: Export compressed data to standard output (output to screen)
-V: Can display the
Description
Cut press the column to split the file and you can specify the delimiters for each column. In cut terms, each column is a field, sometimes the first column, which may be described as the first field.
Actual combat:
Suppose there is a
For example, after more than one system, application installation, we often need to modify a lot of configuration files, with the VI editor means time-consuming, repetitive work, and SED can release us from the heavy duplication of work.
How SED is
First script file
Copy Code code as follows:
#!/bin/bash
echo "This are my I-A-bash code!"
Exit 0
redirect Symbols and mathematical calculations
Copy Code code as follows:
#!/bin/bash
Echo-n "The time and
1. Show the top 10 processes consuming memory/cpu
Copy Code code as follows:
PS aux | Sort-nk +4 | Tail
PS aux | Sort-nk +3 | Tail
2. View process
Arrange by memory from large to small
Copy Code code as follows:
1. View all users in Linux
(1) in the terminal. In fact, only need to view the/etc/passwd file on the line.(2) Look at the third parameter: More than 500, is built behind the user. Others are users of the system.
or use cat/etc/passwd |cut-f 1-d:
Sometimes we need to delete the empty folder recursively, search the internet for a while, did not find a better shell script, so we wrote a
Script
Copy Code code as follows:
#!/bin/bash
# Author: Ten years later, Lou's brother
#
Copy Code code as follows:
[Root@web-server php]#/etc/init.d/httpd Restart
Shell-init:error Retrieving current Directory:getcwd:cannot access parent directories:no such file or directory
This error indicates that the GETCWD command could
1, configure multiple server logs as long as the $website variable is incremented and separated by a space.2, looping to create the log directory3, after the split with XZ compression, of course, can not be installed with Gzip bzip2 and so on.4,
Check to see if the remote port is open to bash:
Copy Code code as follows:
echo >/dev/tcp/8.8.8.8/53 && echo "Open"
To get a process into the background:
Copy Code code as follows:
Ctrl + Z
To move a
Build a Php+mysql platform, the range for DVWA, set the SQL injection range level of low (easy to test use).Enter 1 in the Submit box, grab the package with Burp, copy the package data to the Cookies.txt document, and drag to the Kali
Although Git is a distributed version management system, for team project development, it is common to create a git server on a separate server. Similar to Svn,git server, there are several ways of configuring it. For more information, refer to
the function of the echo command is to display a piece of text on the display, which generally acts as a hint. the general format of the command is: Echo [-n] string where option n means that the output text is not wrapped, the string can be quoted,
Testing and comparison of shell scriptsTest command: Checks the file type and compares the value (depending on the execution result of the expression (true or false), returns an exit status. )NAMETest-check file types and compare
I see in the study not only has the break and the continue existence, as well as break-n and the continue-n existence so what difference does it have.You can then write the test set code:For i in a B c DDoEcho-n $iFor j in ' seq 10 'Doif test $j-eq 5
I have previously written a script similar to mysql full and incremental backup, but it is too simple. Last night, I wrote an instance for mysql5.7 for the company's online server, which is relatively more optimized.Note: This script is only
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