Fortune Telling Collection - Fortune-telling birth date - Linuxshell programming
Linuxshell programming
First, the basics of Shell programming
The basic format of 1 Command process
The basic format of a Shell script is as follows:
```
! /bin/bash
This is a note.
Echo "HelloWorld!"
```
The first line specifies the interpreter of the script, generally/bin/bash; The second line is a comment explaining the role of the script; The third line is the execution command, which is used to output "HelloWorld!" .
2. Shell variables
Shell variables are used to store data and can be defined in the following ways:
```
Name= "Tom"
echo$name
```
Where name is the variable name, Tom is the variable value, and $name is the way to call the variable.
3. Shell operators
Shell supports a variety of operators, such as arithmetic operators, relational operators, logical operators and so on. Here are some commonly used operators:
```
arithmetic operator
a= 10
b=20
Echo' expression $ a+$ b' 30
Relational operator
a= 10
b=20
If [$a-eq$b]
then
Echo "A equals B"
other
Echo "A is not equal to B"
The ship does not bear the loading fee.
Logical operator
a= 10
b=20
if[$a-gt0-a$b-gt0]
then
Echo "A and B are both greater than 0"
other
Echo "A and B are not both greater than 0"
The ship does not bear the loading fee.
```
4. Shell Process Control
Shell process control is used to control the execution of scripts. Commonly used process control statements are if-else, for, while, etc. Here is an example:
```
Foreign exchange USD (seq 1 10)
do
Echo $i
finished
```
The above code will output numbers from 1 to 10.
Second, Shell programming in actual combat
1. Implement file backup
File backup is a common operation, which can be realized by Shell script. The following is a simple file backup script:
```
! /bin/bash
backup file
tar-czvfbackup.tar.gz/home/user
```
The above script backs up files in the /home/user directory to backup.tar.gz files.
2. Realize the timing task
Timed task is a very practical function, which can be realized by Shell script. The following is a scheduled backup script:
```
! /bin/bash
Schedule backup files
whiletrue
do
tar-czvfbackup.tar.gz/home/user
Sleep 3600 犆 犆 犆 犆 犆 犆 犆 犆 犆 犆 犆 犆 犆 犆 犆 犆 犆 犆 犆 犆
finished
```
The above script will back up the files in the /home/user directory every hour.
3. Realize system monitoring
System monitoring is a very important task, which can be realized by Shell script. The following is a simple system monitoring script:
```
! /bin/bash
System monitoring
whiletrue
do
Cpu = ` top-b-n 1 | grep " Cpu " | awk ' { print $ 2+$ 4 } ' '
mem=`free-m|awk'/Mem/{print$3} ' '
Echo"CPU utilization: $cpu% "
Echo "Memory usage: $memMB"
Sleep60, what's wrong?
finished
```
The above script will monitor the usage of CPU and memory once every minute.
- Previous article:The story of Yang Guifei and Litchi
- Next article:How about Yancheng Longzhuo Electronic Commerce Co., Ltd.
- Related articles
- Excuse me, did Maoshan Daoism originate in Jiangxi? Are there any real Maoshan descendants now? Do psychics like Maoshan art really exist?
- Du hired a fortune teller. What did the fortune teller write? After Du, he was bedridden.
- Are there witches or not?
- Xu Maogong calculated that mccullough's birthday was 73. Why did mccullough die young at the age of 23?
- Are oilfield workover workers free to work?
- What is Jet Li's real family background? Who is his grandfather?
- What is an iron egg?
- 1973 may 2 1 birth horoscope fortune telling
- Ten dustpans for fortune telling _ Ten dustpans for fortune telling
- Fuding Wenzhou Mall was built that year.