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
Parameters:-N does not execute script, only checks syntax for errors-V Output the script contents to the screen and execute the script-X executes the script and outputs the content to the screen-N-VTen module () { eval '/usr/bin/modulecmd bash $*'}#/bin/bashif [$15 ];then "Yes"or "else" No " Fiyes-X[[Email protected] sbin]# SH-'['5']' 2operator expected+ echo NonoExpand:Use PS4 to make debugging output line numbers[[email protected] sbin]# echo $PS 4+[[email protected] sbin]# export P
]:~/learn$ cat Args.txt | Xargs SH cecho.sh;Arg1 arg2 arg3#Requirement 3, how do I embed parameters in a fixed command line? As shown below:Copy CodeThe code is as follows:[Email protected]:~/learn$ sh cecho.sh-p args1-1-P args1-1#[Email protected]:~/learn$ sh cecho.sh-p args2-1-P args2-1#[Email protected]sli-pc:~/learn$ sh cecho.sh-p args3-1-P args3-1#Solutions for using Xargs:Copy CodeThe code is as follows:[Email protected]:~/learn$ cat Args.txt | xargs-i {} sh cecho.sh-p {}-1-P arg1-1#-P arg
updated successfully.Changing password for user bruce03.Passwd:all authentication tokens updated successfully.Changing password for user bruce04.Passwd:all authentication tokens updated successfully.Changing password for user bruce05.Passwd:all authentication tokens updated successfully.Changing password for user bruce06.Passwd:all authentication tokens updated successfully.Changing password for user bruce07.Passwd:all authentication tokens updated successfully.Changing password for user bruce0
Write a small script to calculate how many days you have for your birthday.#!/bin/bash# Enter your birthday date, calculate how many days you have birthday #2015 July 20 read-p "Please enter your birthday date (YYYYMMDD):" date1date_d=$ (echo $date 1|grep ' [0-9]\{8\} ') if[ "$date _d" == "];thenecho" You typed the wrong format ... "exit1fideclare-idate_bir=" date --date= "$date 1" +%s ' declare-idate_now= ' date+%s ' declare-idate_left=$ (( $date _bir-$date _now)) declare-idate_d=$ (($date _l
for the second partition;(3) for Rootfs to provide bash, LS, cat programs and the library files that depend on;(4) Provide the configuration file for grub;(5) The new hard disk is set as the first boot item and can start the target host normally;8. Write a script(1) can accept four parameters: Start, stop, restart, statusStart: Output "starting script name finished."...(2) Any other parameters, all error exits;9, write a script to determine whether a given user is logged into the current system
1. List the directory under the current directory (only one level is required)1 #!/bin/bash 2 for f in ' LS ' 3 do 4 if [-D $f] 5 then 6 echo $f 7 fi 8 done2, the current directory of files (only need a level) listed1 #!/bin/bash 2 for f in ' LS ' 3 do 4 if [-F $f] 5 then 6 echo $f 7 fi 8 done[[Email protected] ~]# date +%f "%T" 2016-02-17 15:54:13Knowledge points : In a shell script, if also often judge about the file attributes, such as whether it i
???Because in IO redirection, the standard output is prepared before it is read from the standard input to the standard output. is not a bit around.It's like passing the baton in a relay race; you don't see the guy with the stick, you're definitely not going to send the baton out.So, in the cat 3. How variables are evaluated in a for loopA. Taking values from a set of stringsFor Var in one, three four fiveDoEcho ****************************Echo ' $var is ' $varDoneB. Taking a value from a positi
=" Wkiom1dpl2tdsdtraaaoaz2doqg510.png "/>2. Progress barTo write a simulation progress bar using a shell script:#!/bin/bashstr= "" Arr= ('-"\" | "'/')//define array to simulate cursor rotation for ((i=1; iTo run the program:650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/83/0A/wKioL1dpMCOgKMMxAAAJrNtGHEA737.png "style=" float: none; "title=" Shell3.png "alt=" Wkiol1dpmcogkmmxaaajrntghea737.png "/>650) this.width=650; "src=" Http://s4.51cto.
Share a recently written shell script that enables you to back up the production line files and rollback operations by the file directory structure of the published package.1#!/bin/SH2Path="/home/www/site1"3pub= $path"/release/pub/mboxii/trunk"#发布目录4bak= $path"/release/bak"#生产目录备份文件5Prod=$path #生产目录6pub_file_plus= $path"/release/pub_plus.txt"#增量文件: Publish a new file list log for a package relative to the production package7 8 #执行备份9 Dobak () {Ten #删除
Tags: Configuration ideas nbsp Script Practice post awk bash judgment comparison#!/bin/Bash while : DoRead-P">>>"user [["$user"="Q"]] || [["$user"="Q"]] Break [[-Z $user]] ContinueID$user >/dev/NULL [[ $? -eq0]] Cat/etc/passwd|awk-F:'{print $, $NF}'|grep$user | |Echo "User not exist" DoneThe script implements the target to determine whether the user existsMain ideasThe while do statement implements the loopAdd variable $user exit mechanism use "| |", "", respectively, with operations and or o
the same as [].(4) between multiple [] and multiple [[]], or any of the mixed intermediate logical operators are or | |.1.5 General Examples:(1) Compare the size of the two integers by defining variables, script arguments, and read-in in a conditional expression (prohibit using if) and alerting the user to the results in the form of a screen output. A total of 3 scripts developed, when using script to pass the parameter and read in the way you need to be a variable is a number, and not to give
]
Then
Echo "A is greater than B"
Elif [ $a -lt $b ]
Then
Echo "A is less than B"
Else
echo "None of the condition met"
Fi
Operation Result:A is less than BThe IF ... else statement can also be written as a line and run as a command, like this:
If test $[2*3] -eq $[1+5]; Then echo ' The numbers is equal! ' ; fi;
The IF ... Else statement is also often used in conjunction with the Test command, as follows:
NUM1=$[2*3]
num2=$[1+5]
What is a shell script sampleLet's look at an example:#!/bin/shcd ~mkdir Shell_tutcd shell_tutfor (i=0; iExample explanation
Line 1th: Specify the script interpreter, here is the interpreter with/bin/sh
Line 2nd: Switch to the current user's home directory
Line 3rd: Create a directory Shell_tut
Line 4th: Switch to the Shell_tut directory
Line 5th: Cycle conditions, 10 cycles
Line 6th: Create a test_1 ... 10.txt file
Li
Tags: ges vim editor nginx root user Form bash script expec Ash rsyncObjectiveLearn about the knowledge reserves required for Shell script programming:Vi/vim Editor Command VIMRC set to be proficientBasic commands, more than 100 skilledBasic and common Network Service commands to be: NFS, rsync, INotify, Lanmp, Sersync, SSH keyI. Shell scripting concepts and exam
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.