Unix/linux Shell Programming Combat: Using embedded documents here documents
First, here documents (embedded documents)Here, documents. As a way of redirecting, instructs the shell to start reading the output at the current location of the source
Requirements:No. 0 Step: Write the simplest shell command interpreter, this program is taken from Apue example 1-5, command can not take parameters.What the trainees need to do is as follows:The command interpreter is first a dead loop.Prints a
#========================start shell Script ============================#!/bin/bash# defines the user name and password to use when backing up the database db_user= "root" db _passwd= "111111" #定义FTP服务器地址, user name, password, directory Ftp_url=113.1
Alarm SystemFirst, the alarm system main script(Script storage Address:/usr/local/sbin/)1. Create a script to store the directory: mkdir /usr/local/sbin/mon/ 1.1 creating directories for each functional module---storing scripts CD
In shell development, when we connect to FTP or passwd or sudo, we need to enter the password manually. This is obviously inappropriate for automation. And expect's strong interaction model solves this problem. I am involved in this work, the
1 " *.pid " ` 2 for inch $head _files 3 Do 4 ' {print $} ' | Xargs Kill-95 rm-f $file6 DoneCode as aboveExplain:1. Find all the PID files in the./fmsconf Directory2. Traverse the found file3. Start traversing4. Separate explanations:1. Cat
Kinds:? Set: Used to display local variables, display variables for the current shell, including variables for the current user? ENV: Used to display environment variables and display variables for the current user.? Export: Used to display and set
Pipe symbol |Used to input the output of the previous instruction as the last instruction[email protected]]# Cat 1.txt | Wc-l2[email protected]]# cat 1.txt1.txt2.txt[[email protected]]# find./-type F | Wc-l37Job ControlWhen the process is running,
Shell Special character Cut command
Any of any characters? Any one character#注释字符\ de-Semantic characters·| pipe characterCut intercept string-D Specify delimiter-f Specifies the Intercept paragraphBy looking at what we can see,/etc/passwd is
Bash Knowledge Points: File testing[ ][[ ]]TestMonocular test:-e file: Test files exist-A file: Test files exist-F file: Test for normal files-D directory: test for directory files-H file: Test is a linked file-R somefile: Test whether its valid
Only the environment variables are placed in the configuration file to automatically take effect each time the power-on. SOURCE command: Let the configuration file take effect directly without logging off or logging back in.Source configuration file
Reference: Linux commands, editor and Shell programming, advanced Programming for UNIX environmentsBoth exec and source belong to the Bash Internal command (builtins commands), where you can view all the internal command information by entering man
The script is:nohup/mnt/nand3/h2000g >/dev/null 2>&1 &For & 1 More accurate should be the file descriptor 1, and 1 is generally representative of Stdout_fileno, in fact, this operation is a dup2 (2) call. He standard output to All_result, and then
4.1 Monitoring procedures1. PS defaults to only the processes that are running under the current console that belong to the current user. You can take many options, such as-a for all processes-E, and so on.2. Ps-l View process More informationUID:
If statement format:If condition then statements [elif condition then statements ...] [Else statements] fiThe syntax for the most streamlined if command is:if TEST-COMMANDS; then CONSEQUENT-COMMANDS; fiThe IF condition judgment statement
One, monitoring server system load situation:1, use the uptime command to view the current load situation (1 minutes, 5 minutes, 15 minutes average load situation)# uptime15:43:59 up 186 days, 20:04, 1 user, load average:0.01, 0.02, 0.00Rule of
Shell programming often involves the calculation of numerical values, and sometimes it is easy to forget or confuse the scenarios for these calculation commands, which is a summary of commonly used calculations. The main include let, BC, expr, (())
The pipe command is using the "| "This defining symbolpipe Command "| "can only deal with the correct information coming through the previous command, i.e. Standard Output the information, for Standard Error and there's no direct processing
1, file* popen (const char* cmd,const char* type);int Pclose (file* stream);Popen () function fork () A child process that creates a pipeline for parent-child interprocess communication, which either reads from the pipe or writes to the pipe,
20.16-20.17 functions in the shell
The function is to organize a piece of code into a small unit, and give the small unit a name, when the code is used to call the name of the small unit directly.
格式: function f_name() {
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.