In order to check the network connection status between the daq01 and the blade server,1. Use the output rule of ping command, if can ping pass, will output 0% packet loss value; If you cannot ping the pass, the 0% packet loss is not output2. If the ping command output 0% packet loss successful execution, the network connection is OK, otherwise the network connection is not3. in Shell scripts | | For use, refer to 20360107Command1 Command2Indicates:
content such as/boot is a specific content)$?: The state returned after the previous command was executed, when the return status value is 0 indicates normal execution, and a value other than 0 indicates an exception or errorDetermine if an error occurs correctly for 0 exception error for non 0 value between 1-127$: The currently executing process/program name (which is the name of the currently executing command or program)Tip: Add Environment variablesVim/etc/profileAt the end of the document
file from line 22nd to line 33rd to the end of line 44th.
Sed ' 1,21h;22h;23,33h;44g ' pass
18, move the file from line 22nd to line 33rd to the end of line 44th.
Sed ' 22{h;d};23,33{h;d};44g ' pass
19, only the first word of each line is displayed.
Sed-nr ' s/([^a-z]*) ([a-z]+) ([^a-z]+] (. *)/\2/p '/etc/passwd
20, print the first word and the third word of each line.
Sed-nr ' s/([^a-z]*) ([a-z]+] ([^a-z]+) ([a-z]+] ([^a-z]+) ([a-z]+] (. *)/\2
Think of a long time not updated blog, today in the group to see the discussion about shell script encryption things.Think about it too, we are writing scripts sometimes configure the relevant account and password things, so as long as the permission can see the information, very insecure, there is no normal operation of the file encryption. The following two features are broadly available:
Encrypt files to prevent others from seeing what I w
Http://classroom/pub/materials/userlist[Email protected]/]# vim/root/batchusers#!/bin/bashIf [$#-eq 0];then//$ #位置变量的数量, when no arguments are provided, the $ #为0, the expression is setEcho ' Usage:/root/batchusers ' >2//output Usage:/root/batchusers >2 into error outputExit 1//Return value 1, prompt for wrong input parameterselif [!-F $];thenEcho ' Input file not found ' >2Exit 2FiFor a in $ (cat $)DoUseradd-s/bin/false $aEcho $a created successfullyDone########################################
Summary: Chapter Three discusses the two basic operations that are commonly used when writing shell scripts. The fourth chapter introduces about 30 useful tools for processing text files.Chapter III Find and replaceSummary: This chapter discusses the two basic operations that are commonly used when writing shell scripts: text lookup, text substitution.3.1 Finding textTo remove a specific line of text from t
spaces. If IFS is null, the parameters is joined without intervening separators.oldifs= "$IFS" ifs= "" array= ($result) ifs= "$oldIFS" for I in ${array[@]}; Doecho $idone# Use Facter to get a set of Key-value# Facter output has a newline character, you must replace the newline character with a space# Replace newline characters with spaces to use awk or sed# awk-v rs= "" ' {gsub ("\ n", "");p rint} '# ECHO-E "2 \n1" | Sed ': A; n;$!ba;s/\n//g 'result=$ (facter | awk '/ipaddress/!/ipaddress_lo/{p
#shc是一个专业的加密shell脚本的工具. Its role is to convert the shell script into an executable binary file, which is a good solution to the script contains IP, password and so do not want to open the problem.HTTP://WWW.DATSI.FI.UPM.ES/~FROSAL/SOURCES/SHC's official websitewget http://www.datsi.fi.upm.es/~frosal/sources/shc-3.8.9.tgzTAR-XF shc-3.8.9.tgzCD shc-3.8.9Mkdir-pv/usr/local/man/man1#这步是必须的, because SHC will ins
script requires a user name list file as a parameter2) If no parameters are provided, this script should give a hintUsage:/root/batchusers, exit and return the corresponding value3) If a nonexistent file is provided, this script should give aShow Input file not found, exit and return the corresponding value4) New User login Shell is/bin/false, no need to set password5) User list test file:Http://classroom/pub/materials/userlist# wgethttp://classroom/
Statistics commands sort, WC, uniq
Sortsort [-fbmnrtuk] [file or stdin]-F ignores case-B ignores the front space-m sort by month name-N using pure numeric sorting-R Reverse Sort-U The same data item appears only one item-T delimiter-K to sort by that intervalegcat/etc/passwd | Sort-t ': '-K 1//pair to: Sort the first column of the split
WC statistic Word, line or character numberWC [-LWM]-L Number of rows-W Words-M character CountegCat/etc/profile | Wc-lwm
Uniq duplicate data a
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 '
{Command1Command2Command3}CommentsAs with the shell, the comment uses the #Replace[Address] S/pattern/replacement/flagsThis means that the part of the address line that matches the pattern is replaced with replacement.Of these, flags have several values:A number from N 1 to 512 that represents the substitution of the nth occurrence of the specified pattern in this mode.G makes a global change to all occurrences of the pattern space, and by default onl
To see what versions of the Shell:cat/etc/shells system are currently running, the first process that starts is initHow bash Shell debugs:Simply add parameters after the SH command-N: Do not execute scripts, query the grammar within the scripts, if there are errors are listed!-V: The contents of scripts are displayed on the screen before executing the scripts;-x: The scripts content that will be used is displayed on the screen, slightly different from
' test.in//Print line 3rd to 5th Sed–n '/hello/p ' test.in//print out lines containing hello Sed–n '/hello/= ' test.in//print out line numbers with Hello Sed–n '/hello/d ' test.in//delete the line containing Hello Sed Common editing commands The SED replace command uses the format "Address" s/old word/new word/"GPW" Address: If omitted, indicates that all rows are edited G: Global substitution, default means replacing only the first word to match P: Print the modified line W fname: Writes the
Write a script:1. Add 10 users user1 to User10, password with user name, but only if the user does not exist to add;#!/bin/bash# forIinch{1..Ten}; Do if!IDUser$i >/dev/NULL; ThenUseradd user$iEcho "user$i"|passwd--stdin user$iElse Echo "User$i exists" fi DoneDelete the above 10 users#!/bin/bash# forIinch{1..Ten}; Do if IDUser$i >/dev/NULL; ThenUserdel-r user$i >/dev/nullEcho "user$i deleted" Else Echo "user$i NOT EXISTS" fi DoneExtension: Adds or deletes a specif
Shell script Programming-case OneProgramming Requirements:1. Create a Vm-ctl script, under/bin/2. Implement features: Create a virtual machine, create a virtual machine snapshot, turn on a virtual machine, display a virtual machine, stop a virtual machine, reset a virtual machine.The script achieves the expected result:SH vm-ctl create|nodecreate|start|view|stop|reset VmnameThe implementation script is as follows:#!/bin/bashCase "$" inCreate) # #创建虚拟机
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):
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.