Shell base syntax and monitoring process does not have a restart

Source: Internet
Author: User
Tags function definition

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

Related Article

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.