part is the command, how to execute the command at ordinary times, how to write this place
Two: sftp upload the downloaded shell script
The complete sftp upload script is as follows:
#!/bin/bash#SFTP配置信息#IPip=1.1.1.1#端口Port=22#用户
Shell script structure Example 1, shell script example
Since 2013, I have been lazy and have written a lot less. This year, I plan to summarize my previous accumulated experience.
Start with s
Simple shell-script example and shell-script example
#! /Bin/bash # defind the pathPATH =/usr/localexport PATHread-p "please input your first name:" firstnamereap-p "please input your last name: "lastnameecho-e" \ nyour name is: $
1. When the shell script executes the Python script, you need to use the return value of the Python script to determine the command to be executed by the following program
Example: There are two py programs hello.py
Copy Code code as follows:
def main ():
P
Shell script example: calculate the time difference in milliseconds and microseconds, and shell microseconds
You can use the time command to calculate the execution duration of a command. Although the time command can be precise to milliseconds, the time command cannot calculate the execution time of a bunch of command
The script that recursively iterates through the directory with the shell writes recursively traverses the specified directory and prints the file name under the directory.
Example 1:
Copy Code code as follows:
#!/bin/sh
function Scandir () {
Local Cur_dir Parent_dir Workdir
Workdir=$1
CD ${workdir}
if [${workdir} = "/"]
Then
Cur_dir= ""
Els
their strengths?". If you don't have a clue, or if a project is perfect for using shell commands, but don't know how to use them, I'll give you some insight here. If you are writing an application that provides a variety of backup or file transfer capabilities, you can choose to run the rsync-supported PHP shell script using shell_exec () or one of the other com
A shell script error often occurs when writing a script: write it in windows and copy it to execute it. However, an error is reported when you test it, the error is amazing. for example, the syntaxerrornearunexpectedtokendo error occurs in my for loop statement. be careful... A she
This article mainly introduces an example of a simple Web server implemented by Shell scripts. the Web server implemented in this article is very simple and practical and can be used when you do not want to install nginx, apache, and other large WEB servers, if you need a simple Web server, refer to the next article, which mainly introduces an example of a simple
"server_ip="192.168.88.103"USER="Anonymous"PASS=""FTP=/usr/bin/FTP$FTP-N$SERVER _ip$USERQuote PASS$PASSBinaryget$GET _filenameCD Uploadput$PUT _filenameEOFNote : The FTP username and password are written in clear text in the script, which may be a security risk, separating the user name and password,5. By default, directly with the FTP command and press ENTER will enter the FTP automatic login mode, at this time the FTP command will read the user home
the num2, and the maximum value is num3 forever.#如果输入的不是这样的顺序, you change the order in which the numbers are stored, such as: You can swap the values of NUM1 and num2Tmp=0#如果 NUM1 is greater than num2, swap the values of NUM1 and num2 to ensure that the minimum value is stored in the NUM1 variable.If [$num 1‐gt $num 2];thentmp= $num 1num1= $num 2Num2= $tmpFi#如果 NUM1 is greater than num3, swap num1 and num3 to ensure that the minimum value is stored in the NUM1 variable.If [$num 1‐gt $num 3];the
Example No. 2As a shell writer, often face the problem of inconsistent data format, the data standard session output is a need to solve the problem, this example takes MySQL time as an example, the script enters the month, the day, the year three parameters, standardized aft
A shell script error often occurs when writing a script: Write it in windows and copy it to execute it. However, an error is reported when you test it, the error is amazing. for example, my for loop statement encountered a syntax error near unexpected token do error. I carefully read the
#!/bin/bash# above is the shell script interpreter, which must be written at the beginning to represent the shell script. /bin/sh is more used under UNIX and features less than Bash. Use/bin/bash more, but/bin/sh is/bin/bash soft link in Linux.# Cleanup, version 3Log_dir=/var/log # This defines variables, which general
示进度的函数, quick Screen Display | / ‐ \Rotate_line () {interval=0.1 #设置间隔时间count= "0" #设置 the number of 4 shapes, the default number is 0 (does not represent any image)While:DoCount= ' expr $COUNT + 1 ' #执行循环, COUNT each loop plus 1, (represents 4 different shapes respectively)Case $COUNT The value of the in #判断 COUNT, the shape is not the same as the value shown"1") #值为 1 Display ‐Echo‐e '-' \b\c 'Sleep $INTERVAL;;"2") #值为 2 shows \ \, first \ is escapedEcho‐e ' \ \ ' "\b\c"Sleep $INTERVAL;;"3") #
1. Batch Add UsersCreate a TXT file for the user name and password combination userdata.txt, as follows:123123 123 123 123 123The script to add the above users in bulk is:#! /bin/Bash whileRead Line Dousername=$(Echo$line |Cut-f1-d' ') #或 username=$ (Echo$line |awk '{print $s 1}') Password=$(Echo$line |Cut-f2-d' ') #或 password=$ (Echo$line |awk '{print $s 2}') Useradd $usernameif[$?-eq0]; Then Echo$password |passwd--stdin $usernameElse
supposed to be circulating 5 times, why the cycle of 10 times? , the original addusers.txt is separated by a space, while the for loop reads the file, any whitespace character can be read as a delimiter. The following is an example of a while loop:[[Email protected] ~ ]$ vim useradd_while01.sh[[email protected] ~ ]$ Cat useradd_while01.sh #!/bin/Bashcount=0 whileRead LINES Doecho $LINES let COUNT+=1 DoneAddusers.txtechoecho"$ looped $COUNT times" [em
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.