Operation and Application Instance in shell Based on linux

Posted by superdan_35 on Sat, 11 May 2019 20:20:51 +0200

Operation modes and symbols:

Operational Symbolic Meaning (*Common for Marking)
+, -addition, subtraction
 *, /,%Multiplication, Division, Remaining
 **Power operation
 ++, --self-increasing, self-decreasing
 <,<=,>,>=Comparison Symbol
 =, +=, -=, *=, /=,%=assignment
 For example, a+=1 equals a=a+1

Common operation commands in SHELL:

Operational operations and meaning of operational commands
 (). Operate with integers
 let is used for integer operations, similar to ())
expr is used for integer calculation and has more functions
 Calculator under BC Linux for integer and decimal operations
 $[] User Integer Calculation

A simple demonstration of the operation command:

[root@localhost mnt]# ((a=1+1)) ((()) command
[root@localhost mnt]# echo $a
2
[root@localhost mnt]# Let a=1+1 let command
[root@localhost mnt]# echo $a
2
[root@localhost mnt]# a=1+1
[root@localhost mnt]# Let a=1+1 let command
[root@localhost mnt]# echo $a
2
[root@localhost mnt]# a=1+1
[root@localhost mnt]# echo $a
1+1
[root@localhost mnt]# Echo `expr 1 + 1`expr command
2
[root@localhost mnt]# BC < < EOF BC Calculator Command
> 1+2
> EOF
3
[root@localhost mnt]# echo $[1+1] $[] command
2
[root@localhost mnt]# echo $[2**3] power operation
8
[root@localhost mnt]# echo $[2*3] multiplication
6

Simple for statement:

[root@localhost mnt]# ls
[root@localhost mnt]# vim for.sh

[root@localhost mnt]# sh for.sh 
0
1
2
3
4
5
6
7
8
9

for statement implementation does not output 4 in 1..10:

[root@localhost mnt]# vim for.sh script 1

[root@localhost mnt]# sh for.sh call script
1
2
3
5
6
7
8
9
10

[root@localhost mnt]# VIM for 1.sh script 2

[root@localhost mnt]# SH for 1.sh call script
1
2
3
5
6
7
8
9
10

Write a 10-second countdown script with operations and shell statements you've learned:

[root@localhost mnt]# Scripting vim countdown.sh

[root@localhost mnt]# sh countdown.sh call

Write a script that counts down 1 minute to 10 seconds with operations and shell statements you have already learned:

(scripts display countdown with read interactive command)

[root@localhost mnt]# vim countdown1.sh scripting

[root@localhost mnt]# sh countdown1.sh  call
please input minute:2     Interactive input countdown of minutes and seconds to execute
please input second:10

Script:

Making a calculator from the above commands requires the following
 Display after executing Calculator.sh
 Please enter the number you want to operate on:
Enter the operation to operate on:
Enter the second number to operate on:
> Display values after execution <>
[root@localhost mnt]# Scripting vim Calculator.sh

[root@localhost mnt]# sh Calculator.sh 
please input first int number: 1
please input calculator tactique: +   Verify Addition
please input second int number: 1.2
2.2
[root@localhost mnt]# sh Calculator.sh 
please input first int number: 2
please input calculator tactique: *   Verify Multiplication
please input second int number: 3
6
[root@localhost mnt]# sh Calculator.sh 
please input first int number: 6
please input calculator tactique: /   Verify Division
please input second int number: 2.2
2

Database backup:

Execute db_dump.sh westos (database password)
After the script executes, all libraries in the database are backed up to the / mnt/mysqldump directory
 in
 The backup file name is Library Name.sql Error and ask for action when this file exists
 do
 Enter "S" to skip backup and backup "Library Name.sql" file when "B" is entered
 For Library Name_backup.sql, overwrite source file when "O" is entered

Example of automatic service deployment:

Execute script lamp.sh
 After the script executes, deploy the forums and set apache's network interface to 8080

Autologon script:

Execute auto_ssh.sh 172.25.254.100 westos
 172.25.254.100 is ip
 westos is the password
 Automatically log on to 172.25.254.100 and stay logged on after executing the script

Batch script:

Detect all hosts open in the classroom and grab the check-in names and IPS of all hosts
 Corresponding list, save the list in the / mnt/ip_host.list file

Topics: calculator vim shell Database