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):
Create two scripts in the system bin directory, respectively, Pssh tsshPssh#!/usr/bin/expect-fSet IP [lindex$argv 0]set Port [lindex$argv 1]set Password [lindex$argv 2]set TimeoutTenspawn ssh [email protected]$ip-P$portExpect {"*yes/no"{Send "yes\r"; Exp_continue}"*password:"{Send "$password \ r"}}interactTssh#!/bin/shEcho"here is a list of all your servers"Echo"1.A Server 192.168.100.11"Echo"2.B Server 192.168.100.12"Echo"3.C Server 192.168.100.13"Echo"0. Temporarily do not want to log in"Echo"
Write a script, create a folder, enter a folder, and then use the loop to create a sequential file in the folderIdea: 1. Create the specified folder and go to the folder2. Specify a variable with a value of 0 to allow this variable to be recycled3. Create one document at a time for Each loop until the end of the loopVim create.sh#!/bin/bash#written by Lizheng#about Create FileCD ~mkdir testfileCD testfilefor ((i=0; iTouch Testfile_$i.txtDone650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/
Enter 2 numbers (x, y) if x equals Y, the output is z=x+y, if x is greater than Y, the output is z=x-y, otherwise the output z=x+yVI number2.sh#!/bin/bash#written by Lizheng#about Panduanecho "Please enter the number"Read XRead Yif test $x-eq $yThen echo "z= $x-$y"Elif Test $x-gt $yThen echo "z= $x-$y"else echo "z= $x + $y"Fi650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M00/8B/50/wKioL1hJd0rB2jlvAAALxj75lmM431.png-wh_500x0-wm_3 -wmp_4-s_3050974245.png "style=" Float:none; "title=" 333.p
Example 1. Enter any two numbers and make a judgmentVI number.sh#!/bin/bash#written by Lizhengecho "Please enter the number"Read aRead Bif test $a-eq $bThen echo "The No.2"Elif Test $a-gt $bThen echo "The > no.2"else echo "The Fi650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M02/8B/40/wKioL1hIKCagQPMiAAAYfWCqQ_8745.png-wh_500x0-wm_3 -wmp_4-s_1863110480.png "title=" 555.png "alt=" Wkiol1hikcagqpmiaaayfwcqq_8745.png-wh_50 "/>Shell
Because some registered user account rules can follow, and usually people's awareness of the poor, the password is relatively simple, the user name of the common password login test, to break the password.For learning purposes only, do not use for illegal use. The code has been partially modified, does not work properly, the test needs to modify the code according to the actual needs, in addition to the password security issues must be enough attention.Design ideas:
Intercept HTTP packets
TopicWrite a script1. Pass a parameter to the script, this parameter is the user name;2. If the user exists, perform the following tasks* If the user's ID number is less than 500, display it as an administrator or system user;* Otherwise, display it as a normal user;3. If the user does not exist, add it;Answer#!/bin/bashUsername= $if["$username"=""]; Then Echo "Please input a username" Exit 1fiifId$username>/dev/null; Thenuserid=$ (id-u$username)if[$userid -lt -]; Then Echo "$usern
CTRL key[: Graph:] or [:p rint:] denotes ASCII 33-126 characters[: xdigit:] = 16 binary number [0-9a-f-a-f]Example:grep ^[[:upper:]] file finds lines beginning with uppercase letters in a line characterPOSIX characters need to be enclosed in [].6. Exact matchgrep "\Must have a quoted number7. Or character (extended regular expression character)Grep-e "Ou|se" matches rows with OUs or SE8.egrep and FgrepEgrep "Ou|se" fileEgrep "^-+b" file match begins with a "-" or "-" and a line containing B is
Distance from the last write and a period of time, the period has been followed by private food learning, or did not develop a regular record of the habit, today to write the first script.After a few days of accumulation, learning the next shell script writing, the current master is not too mature, everything is certainly right from the beginning, write a simple bar (difficult will not write O (╯-╰) o).The way this script is executed is to enter the b
: $*"(Note: e.g.--AB cannot be processed when the option is merged if the above operation can only handle a single option)2.3.4 getopt command, for option formatting, e.g:The colon after #!/bin/sh# B indicates that the B option has parameter set--' getopt ab:c ' [email protected] ' while [-N ' $ ']do case ' $ ' in-a ) echo ' Opt Ion a ";; -b) value= "$" echo "Option B, Value is $value" shift; -c) echo "Option C";; --) shift break ;; Esac Shiftdoneecho "T
Break is to jump out of the current loop, and continue is to jump out of the loop and start the new loop again[Email protected] test]#CatDemo.SH #/bin/Bash while true; DoRead-P"Please input number:"x yif((x>9)); ThenContinueelif((y>9)); Then BreakElseZ=$ ((x+y))Echo$zfi DoneEcho "Execution completed!"[email protected] test]#SHDemo.SHPlease input number:1 23Please input number:Ten 2 # $x >9, when the back part of the secondary loop is not executing, and the loop starts againPlease input number
行脚本参数的个数Echo '$*='$* #所有参数变成一个字符Echo '[Email protected]='[email protected] #所有参数basename$0 #获取文件名dirname$0 #获取文件的目录[email protected] sbin]#SH/usr/local/sbin/test.SHAA bb$0=/usr/local/sbin/test.SH$1=aa$#=2$*=AA Bb[email protected]=AA bbtest.SH/usr/local/sbinProcess state variables$? Gets the return value that executes the last command (0 is successful, others are failed)$$ getting the PID of the current shell$_ gets the last parameter of the previous c
Tags:tty a regular expression devproject passwd regular penwho #!/bin/bash-#echo do what exetuate this project \nprintf "Please input your passwd" Stty-echoread Pass Shell Scripting Learning-2
Tags: meaning cond centos7 test cat size pre BER syntax errorNote: The comparison string in the shell can only be used = =, Compare numbers using-eq,-ne,-gt,-ge,-lt,-le, or = =, [[Email protected]SH]$CatNumber_compare.SH #!/bin/bash# script Name: Number_compare.SH#用途: Compare two digit sizesEcho "Please input first number :"Read xEcho "You first number x= $x"Read-P"Please input second number:"yEcho "You second number y= $y"if[$x-eq $y]; Then Echo
Shell BASICS (3) -- quotation marks and shell basics -- quotation marks
--- Today, the space is relatively small; only quotation marks are introduced.
There are three types of quotation marks in shell: Double quotation marks ", single quotation marks", and reverse quotation
BKJIA Translation: It feels great when you understand Shell scripts and can write them smoothly whenever needed. In this chapter, we will teach you how to use scripting to perform complex mathematical operations.
Let's start with the Fibonacci series.
The Fibonacci series, also known as the Golden split series, refers to a series of 0, 1, 1, 2, 3, 5, 8, 13, 21 ......, Each of its items is the sum of the fir
1) View PHP running users:System (' id-a ');?>General PHP running user is Apache2) do a key trust for Apache users:2.1)First look at the Apache user information:# Su-apacheThis account was currently not available.# Cat/etc/passwd|grep ApacheApache:x:48:48:apache:/var/www:/sbin/nologinSwitchApache:x:48:48:apache:/var/www:/bin/bash2.2)Root User action:Mkdir/var/www/.sshChown Apache. /var/www/.ssh2.3)Then switch to Apache User:Su-apacheSSH-KEYGEN-T RSA2.4)Root user, and finally change back to Nolog
Recently do the computer room bandwidth detection. Recently wrote a shell script to ping the IP of the machine room in bulk, returning the failure rate and the average response time#!/bin/bashlog=$1.logecho-n "" > $logfor i in ' Cat $ do/bin/ping-s 1000-f-C $i > Ip.txtecho "' Curl ip.cn? ip= $i ' Cat Ip.txt |grep transmitted |Gawk ' {print $6} ' cat Ip.txt |grep avg | Gawk-f/' {print $} ' >> $logdonerm-rf ip.txtStore all IP required for detection in t
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.