Alibabacloud.com offers a wide variety of articles about linux shell scripting cookbook, easily find your linux shell scripting cookbook information here online.
Recall a thing: Before using Linux to find Chinese input method, in Baidu entered the FCITX, and then the result has a, you are looking for is not: satirical Tencent. Originally can not remember this input method name, but later brother remember this input method name is how to spell, thanks to Baidu.
Nineth Chapter Awk's amazing performance
The invocation of awk can define variables, providers, and specify input files, syntax:
Copy Code cod
Security code: Waves will sometimes, straight hanging cloud sail sea Shell scripting App (iii)Foreword: It is difficult to write all the code in sequential order when it is hard to satisfy the requirements when facing various lists and repeating tasks. Use other program control structures such as loops, branches, and more to make it easier to perform more complex and powerful functions.1. Use a For Loop sta
"! -name "DB"! -name "rtx*" ' ">>/shell/bAckup.logElseecho "' Date +%y%m%d ' Delete unsuccessful" >>/shell/backup.logFi# from Email adminMail-s "DataBackup" [email protected] If [$WEEK-ne 0];thenif [!-d/hddf/database/' Date +%y%m%d '];thenMkdir-p/hddf/database/' Date +%y%m%d 'mv/hddf/database/{*.bak,*. BAK}/hddf/database/' Date +%y%m%d '/FiElseecho "Today is Sunday no data backup" >>/
I. OverviewIf you need to use a scheduled task to complete some business in your project, there are generally two approaches: timed tasks depend on the project, scheduled tasks are started with batch processing (Windows execution) or shell scripts (Linux), and are not dependent on the project.Personally, the timing task does not depend on the project way more excellent! Independent execution, without affect
Head> 3 title>Test Python Web servertitle>4 Head>5 Body>6This is a test Python Web server,b>Hello!b>7 Body>8 HTML>View CodeHistory |awk ' {cmd[$ 2]++; count++;}END {for (a in CMD) print cmd[A] "" cmd[a]/count* "%" A} ' |Grep-v "./" |Column-c3-s ""-t |Sort-nr |NL | Head-n10 This line of script can output your most commonly used 10 commands, so you can even insight into what kind of programmer you are. Do you know the code? It doesn't matter, the system learns * nix
Direcotry" fiOperation Result:$ sh test.sh13File is an ordinary fileNot Direcotrymay also be unfamiliar with some of the above operators, with a detailed list of operators below.
Operator
Description
-B File
Detects if the file is a block device file, and returns True if it is.
-C file
Detects if the file is a character device file, and returns True if it is
-D File
Detects if the file is a directory, and
Tags: shell scriptOne, Shell scriptScript: Can execute the file, after running can implement some function (command stack, non-interactive)Standardize the general composition of shell scripts#! Environmental Statement (Sha-bang)# comment TextExecutable codeSecond, simply write a shell script, according to international
big side.Listen to the old boy teacher and some experts said that the best way to learn early is to knock and break the problem of practice.The highest programming self-perception is:Problem analysis decomposition is fast and complete.Completeness: is to judge the various possibilities.High efficiency, high performance, 1+2+3...+100 = (1+100) * (100/2)/2Old boy Shell advanced programming combat Video 52 freeHttp://edu.51cto.com/course/course_id-963.h
First, the basicView all shellsCat/etc/shells or Chsh–l1. Examples of scripts.Linux does not differentiate files, for the convenience of memory, here with. Sh end.(1) Vim first.sh#!/bin/bashMkdir/root/shellIfconfig(2) Add Execute permissions chmod +x first.sh The file will turn green at this point.(3) Execution: 5 ways:①./first.sh② Absolute Path execution③sh + script name (no execute permission required)④source + script name (does not require EXECUTE permission) recommended use⑤. + PIN NameTip:
Learning two months of Linux, remember a lot of commands, know the role of the script, also by the script killed about half of the brain cells, and now the script is not skilled use, feel lost. Love my brain cells, hate the script, but have to say that the script is a good thing ah, it is really convenient to use, but write it really burn the head! The following summary of this week to learn the scripting s
)Redirect in-depth explanationIn general, each Unix/linux command will open three files when it is run:
Standard input file (stdin): stdin file descriptor for 0,unix program reads data from stdin by default.
Standard output file (stdout): StdOut file descriptor for 1,unix program defaults to stdout output data
Standard error file (stderr): The stderr file descriptor for the 2,unix program writes an error message to the stderr stream.
True when the length of a string is greater than 0
-Z str1
True when the length of a string is 0
Str
True when the string is non-empty
As an example, compare strings to test the user id:If ["$ (whoami)"! = ' root ']; Thenecho "You had no permission to run $ as Non-root user."Exit 1;Fi
Numeric comparison (integer)
operator
Compare Results
Num1-eq num2
Two numbers equal to True
How to protect a shell program you've writtenTo protect your own shell scripting program, there are many methods, the simplest way there are two: 1, encryption 2, set the expiration time, following the SHC tool as an example description:I. Download and install the SHC toolSHC is a tool for encrypting shell scripts. Its
The main contents of this section:Top command to count CPU utilizationOne, problem analysisMySQL is multi-threaded under Linux and can only distribute multiple threads to a single CPU.Therefore, using a small server, or PC server, multiple CPU utilization is not high.Basically one or two are in use.This section shares the statistical CPU utilization method, for everyone to learn the reference.Related reading:View
1.Shell command line writing rules:Multiple commands can be executed on a command line, but required;Long command statements can be expanded with \ on the command line2. Execute Shell Program2.1./test.sh2.2 Bash test.sh2.3 In order to compile and execute the shell-written program in any directory, add the/bin directory to the entire environment variableExport Pat
Tag: The grep command of the Shell scripting toolgrep (abbreviated from globally search a Regular expression and Print) is a powerful text-search tool for Linux systems that can search for text using regular expressions , and print out the matching lines. Egrep and Fgrep are grep extensions that support more re- metacharacters ,fgrep is fixed grep or fast Grep.li
0. IntroductionPrepare to open a new pit and update a shell practice every day. Because shell scripts belong to the kind of skills that are unfamiliar or even forgotten when you're not practicing, I can only keep on practicing in order to resist the drag of forgetting.1. First day Practice topicsTopicPlease generate a daily file according to the date format (XXXX-XX-XX), for example, the file generated toda
Remotely copy a file to the specified directory on the specified IP machine:./scp_file.sh/tmp/xx.sh/tmp/test/echo "Copy the file to the $ $ directory!" "For IP in 192.168.60.243 192.168.60.244 192.168.60.245 192.168.60.246 192.168.60.248do scp-r" [email protected] $IP: $ echo "SCP $ $ip is: $?"Doneecho "$? Distribution Complete!! "Remote execution of the specified shell file command on the specified IP machine (requires SSH support) (with parameters):
are currently using[Email protected] conf]# echo $BASH/bin/bash2 script +x to debug, troubleshoot errors[[email protected] sh]#/bin/bash-x variable.sh + hellovariable.sh: line 2:hello: Command not found + a=123+ echo ' Print variables equal I S 123 ' Print variables equal is 1233-E \ n line breakEcho-e "Start scripts. \ n .... "4-E \033[32m \033[0m Promise color [32m can be changed to 33/34/35/36 color]Echo-e "\033[32m start scripts. \n....\033[0m "5 Linux
Common shell scripting use cases, from the online reference and after the modification of the work, in addition to the wiki in the company to write records, it is necessary for a blog to record a drop.Combat Problem 1:Use the For loop to create a batch of 10 files in the/oldboy directory, with the name in turn:Oldboy-1Oldboy-2......Oldboy-10Answer:[[Email protected]]# cat 1.sh#!/bin/bashFor iin ' seq 1 10 '
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.