1. Script instance
Save the following script as getftp.sh
# !/bin/bash datesign= ' date-d -95day +%y%m%d ' ftp -NV 12.2.2.28 <<! Ftprunuser User01 User01 Prompt bin CD TXT LCD /app/info/getftpmget ${datesign}*. Txtbye! Ftprun
Script Description:
#!/bin/bash
#表明该文本的内容为SHELL命令 datesign= ' date-d -95day +%y%m%d '
#声明变量datesign, used to record the date label that needs to get the file name. #-95day represents the number of days away from the system time, if today is 20121123, #-2day represents 20121121.
#%y represents the year, such as 2012,%y also represents the year, but the format of the #%m for the month, such as one by one #%d represents the day, such as 23
#同样,%h,%m,%s a distinct expression of time and seconds,
#以系统时间为2012年11月23日10时55分44秒为例
# ' Date–d-2day +%y-%m-%d%h:%m:%s ' values are: 20121121 10:55:44 ftp-nv 12.2.2.28 <<! Ftprun
#登录FTP服务器, 12.2.2.28 represents the IP address of the FTP server
#从! Ftprun to the end of the code! Ftprun is an FTP command. #! Ftprun is his own random name. User User01 User01
#给出FTP的用户名和密码. Here the user name and password are: User01 Prompt
#该命令忽略FTP交互 Bin
#二进制格式传送 CD TXT
#TXT表示数据文件在FTP服务器上的目录. Lcd/app/info/getftp
#/app/info/getftp data file to download to the server directory Mget ${datesign}*.txt
#需要下载的文件, ${datesign} is the previously declared variable, * represents a wildcard Bye
#FTP完成退出! Ftprun
2. Execute the script to make it call periodically
When the shell file executes, there may be a problem with special characters. You need to convert the getftp.sh file to a format. Can be executed directly under Linux ( if it cannot be run, it can be given permission to execute after running chmod +x./getftp.sh):
dos2unix/app/info/getftp/getftp.sh
/app/info/getftp is the directory where the getftp.sh script resides.
The vi Editor can be tested according to the actual environment to make the script change accordingly. 3. The automatic execution configuration is performed under Linux:
crontab–e * 5 * * */app/info/getftp/getftp.sh
Save exit. The code will run automatically 5:00 every day.
attached: Cron Scheduler Process Description
Cron is the main scheduling process for a system that can run jobs without human intervention. There is a command called Crontab that allows the user to submit, edit, or delete the corresponding job. Each user can have a crontab file to hold the dispatch information. You can use it to run any shell script or a command, run hourly, or three times a week, depending on you. Each user can have their own crontab file, but in a larger system, the system administrator will generally prohibit these files, but only the entire system to keep one such file. System administrators prohibit or allow users to own their own crontab files through the Cron.deny and cron.allow two files.
Crontab's Domain
To be able to run a job at a specific time, you need to understand the meaning and format of each field in each entry in the crontab file.
here are the fields: 1th column min 9
2nd Hour 3 (0 means midnight) 3rd Liege 1 4th column Month 1~1 2
the 5th column of the week 0~6 (0 for Sunday) is the example format of the command crontab to run in the 6th column:
The following is the format of C R o N T a b:
[] When [] day [] month [] week [] the command to run where [] represents a space.
an entry for the crontab file is read from the left, the first column is divided, and the last column is the command to run, which is at the back of the week. In these fields, you can use a bar-to represent a time range, for example, if you want to run a job from Monday to Friday, it can be represented by 1-5 in the day of the week. You can also use the comma "," in these fields, for example, if you want to run a job in Monday and Thursday, you only need to use 1, 4来. You can use an asterisk * to represent a continuous period of time. If you do not have a special qualification for a field that represents time, you should also fill in the field with *. Each entry for the file must contain 5 time fields, separated by a space between each domain. All comment lines in the file are represented by # at the beginning of the row. Crontab Entry Examples
21* * */apps/bin/cleanup.sh
The above example indicates that the/apps/bin directory is running at the cleanup.sh of 21:30 per night. 4 1,10,22 * */apps/bin/backup.sh
The above example shows the backup.sh of the 1, 1 0, and 2 2nd of the month of the 4:45 running/apps/bin directory. 1 * * 6,0/bin/find-name "core"-exec RM {} The example above indicates that every Saturday, Sunday of 1:10 runs a find command. 0,30 18-23 * * */apps/bin/dbcheck.sh
The above example shows that the dbcheck.sh in the/apps/bin/directory runs every 30 minutes from 18:00 to 23:00 every day.
0 * * 6/apps/bin/qtrend.sh
The above example shows the 11:00pm running the/apps/bin directory qtrend.sh every Saturday.
Thanks: Thank you for your patience and reading!
FTP timed bulk download files (shell scripts and how to use them)