transcoding
# Dos2unix./test.sh
Permissions
#chmod a+x./test.sh
Grammar
Variable
Var= "111"
Echo $var
Echo ${var}
Operation
no1=4;
no2=5;
Let Result=no1+no2
echo $result;
Self-increment self-reduction
Let no++
Let no--
[] and let similar
result=$[No1 + NO2]
result=$[$no 1 + 5]
can also use (()), but when using (()). The variable name needs to be preceded by $
result=$ (($no 1 + 5))
Expr can also be used for basic arithmetic operations
result= ' Expr 3+4 '
result=$ (Expr $no 1 + 5)
The above does not support floating point
BC Can float
echo "4*0.56" |BC output 2.24
Descriptive descriptors for documents
0 1 2 standard input and output standard error
Redirect to Text
echo "123" > Temp.txt
Additional
echo "123" >> Temp.txt
View File Contents
Cat Temp.txt
Cat 1.txt 2.txt + content
LS +
Invalid parameter output error message stderr
Command error and return a non-0 exit status
Completed successfully returns the number 0
Exit status can be obtained from the special variable $, execute echo $ immediately after the command is executed. You can print exit status
ls + >out.txt error message cannot be output to text
ls + 2>out.txt error message can be output to text
StdErr and StdOut each
CMD 2>stderr.txt 1>stdout.txt
stderr conversion to stdout
CMD 2>&1 out.txt
Or
CMD &> out.txt
StdErr Redirect to
/dev/null
Read Date
Date
function definition
function fname ()
{
return 0;
}
Function call
$fname;
$fname arg1 arg2;
Be sure to note the [] space
#! /bin/sha=4;b=5;if ["$a" = "$b"]; Thenecho "1111" #####
#! /bin/sha=4;b=5;if [ "$a"-eq "$b" ]thenecho "yyyyyyyyyy" Elseecho "nnnnn" fi#####
#! /bin/shps aux|grep redis-stat | grep-v grep| wc-la=11b=11if [$a-eq $b]thenecho "START process ... elseecho" Runi Ng ..... "fi#####
Note the need for < (())
The following monitoring Redis process does not exist before restarting
#! /bin/shp= "Redis-server" Proc_num () { num= ' ps aux|grep $p | grep-v grep| wc-l ' return $num}proc_numn=$?if (("$n" < 1) thenecho $necho "Start redis-server process ..." Elseecho $necho "Redis-server runing OK." fi#####
CRONTAB-E Monitor once per minute
*/1 * * * * /redis.sh
Reference: "Linux shell Script Raiders (2nd edition)"
Comparison of strings and values in the shell
Simple implementation of Linux process monitoring and self-initiated reboots
Shell base syntax and monitoring process does not have a restart