Environment Variables Section:1. View Global variables: printenv/env2. Displays the value of a single environment variable: Echo as Echo $HOME3. Display all environment variables set for a particular process: set4. Setting global variables: Creating local environment variables--exporting to the global environmentCreate local environment variables (use all lowercase to differentiate from system variables)Test= ' Testing a long string '//environment variable name, equals, value no space betweenExp
The test command in the shell is used to check whether a condition is valid, and it can be tested in three aspects, such as numeric value, character, and file.
Numerical test
Parameters
Description
-eq
is equal to True
-ne
Not equal to True
-gt
is greater than is true
-ge
Greater than or equal to true
-lt
is l
[Introduction to awk: ]awk can get some of the content from a single text, or format the text so that it is output in some way.[awk Workflow: ]awk will take the file line into memory and then segment the line (by default by Space or tab, $, $, $ ...). Then delete, then read the second line of content to memory ...Format: awk ' {/pattern/command1; command2;..} ' file # matches this line of the pattern to execute commands such as: Who | awk ' {print '} ' # prints the first chunk of the segment,
input 1:[[email protected] --shiyan rec]#Catrecord1#!/bin/Bash#filename:record.SHdir=/tmp/Recread-P"Please input the session filename:"Filenamesesfile="$dir/$filename. Session"logfile="$dir/$filename. Timing.log"if[ -e $sesfile] Then Echo "$sesfile is exsit,creat session file fault!"Read-P"If you want to reload the file? [y/n]:"Flagif["$flag"="Y" ] Then RM$sesfile $logfile Script-T2> $logfile-a $sesfileElse Echo "Nothing to do!" fiElse
[Sed introduction:]
Sed is a good file processing tool. It is a pipeline command and can be used to add, select, replace, or delete data rows. Sed command line format: sed [-nefri] 'range command' file such as: sed '2d 'aaa.txt # Delete the second line from the aaa.txt file
[Sed workflow:]
When using the vim Screen Editor to edit a file, we need to open the file
''Causes sed Command Parsing to fail. The experiment is as follows:
Try to replace a single backslash with two backlash, that is\ Replace \\
$ Cat t1.sh#! /Bin/shA = 'echo 1 | SED's/\/g''Echo $
$./T1.shSed:-e expression #1, character 8: unterminated's 'COMMAND
$ Sh-X./t3.sh++ Echo 1++Sed's/\/G'Sed:-e expression #1, character 8: unterminated's 'COMMAND+ A =+ E
Chapter 2: compile a script utility to monitor the function du required by the disk space, display the disk usage of files and directories, and view the size of a directory. we can: $ du -- max-depth = 0-handroid-sdk61Gandroid-sdk $ du-shandroid-sdk
Chapter 2: script utilities
Disk space monitoring
Required functions
Du: displays the disk usage of files and directories.
To view the size of a directory, we c
-release
CAT/etc/issue
Chkconfig is frequently used in command line operations. It allows you to conveniently set the services started at the running level of each system. You can easily manage your startup services.
To list the startup status of all services in the system:# Chkconfig-list
To list the mysqld service settings:# Chkconfig-list mysqld
Set mysqld to be used for startup at levels 3 and 5:# Chkconfig-level 35 mysqld on-Level 35
Cut-and
The Cut command extracts text columns from a text file or text stream.
Cut syntax
[root@www ~]# cut-d ' delimited character '-f fields
The PATH variable is as follows
[Root@www ~]# echo $PATH
/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/x11r6/bin:/usr/games
# 1 | 2 | 3 | 4 | 5 | 6 | 7
Take the path variable out and I'll find the fifth path.
#echo $PATH | Cut-d ': '-F 5
/usr/local/bin
Take the pa
of the warehouse.
Baseurl=file:///media/cdrom: The available methods include FTP (ftp://. ), HTTP (/. ), local (file:///. )。
Enabled=1: Sets whether this source is available, 1 is available, and 0 is disabled.
Gpgcheck=1: Sets whether this source verifies the file, 1 for the checksum, and 0 for the non-checksum.
Gpgkey=file:///media/cdrom/rpm-gpg-key-redhat-release: If the above parameter turns on the checksum, then specify the public
Tags: shell script structure, date command, variables20.1 Shell IntroductionShell is a scripting languageYou can use logical judgments, loops, and other syntaxCustomizable functionsThe shell is a collection of system commandsShell scripts enable automated operations, which c
common modulesExample: Viewing the last two rows of a remote host's passwd[Email protected] ansible]# ansible testservers-m command-a ' tail-2/etc/passwd ' 192.168.100.131 |Success | Rc=0 >>postfix:x:89:89::/var/spool/postfix:/sbin/nologinsshd:x:74:74:privilege-separated SSH:/var/empty/sshd:/sbin/nologin192.168.100.132 |Success | Rc=0 >>sshd:x:74:74:privilege-separated Ssh:/var/empty/sshd:/sbin/nologintcpdump:x:72:72::/:/sbin/nologinUse parameters to
Chapter Description :This section will teach you how to use the Vim editor to write documents , configure host names , network card parameters , and the Yum repository , and be familiar with the various modes and command shortcuts.We can finally write a simple and practical shell script by placing the Linux command int
Positional parameters can be moved left with the shift command. For example, shift 3 means that the original $ $ is now $, the original $ $, and so on, the original $ $, $ $, $ $ no move. The shift command with no parameters is equal to shift 1.
Very useful Unix command: Shift. We know that for positional variables or
Tags: shell script structure, date command, variables20.5 logical judgments in shell scriptsLogical ExpressionsIn the [] bracket:-lt:=little than less than-le:=little equal less than equals-eq:=equal equals-ne:=no Equal Not equal to-gt:=greater than greater than-ge:=greater equal greater than or equalIn (()) parenthe
Actual production caseThe production room self-built PPTP client is connected to the production room by dial-up, but once the client network is accidentally disconnected and then dialed againGenerates an IP conflict, so a script is written to monitor whether PPTP IP is multiple (2 IPs will be generated after a general conflict)#!/bin/bash#author liuyueming. /etc/profile #开始没有加这个环境变量for i in {10..35}do n= ' ifconfig|grep 10.13.0.${i}|wc-l ' #循环取ip
main function of the argv[1], argv[2]...$# equivalent to the C language main function argc-1, note that there is no comment behind the # [email Protected] represents the parameter list "$" ..., for example, can be used in the for loop in the back. $* represents the parameter list "$" "$" ..., the same as $? Exit status$$ The current process number of the previous commandUse of functions:Foo () { echo "$-$"}echo "Start call foo" foo
hello (?) ) Represents a characterAn asterisk (*) represents 0 or more characters[] Bracket Matching[! ] An exclamation mark sends out unwanted content.Ls-t sort the latest modification time sortDirectory under AGF.4, AFD02,A1.TXT,BCATT,BD1TX file day01,day02,day03 three directories please find a file or directory that does not start with the letter A, not a file or directory ending in 1, find the first letter with a and the second letter is any , the third letter A-Z, the fourth character arbi
Tags: mem linux shell Shell script Linux ops arppingingRequirements: Use the free command to accurately monitor RAM utilizationKnowledge: GREP,FREE,AWK,BCThe script is as follows[[emailprotected] scripts]# cat mem.sh #!/bin/bash-# free-m represents output in m units, and if
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.