FTP timed bulk download files (shell scripts and how to use them)

Source: Internet
Author: User
Tags time and seconds

Ftp-v-d-i-n-g [host name], where
-V Displays all the response information for the remote server;
-N Limit FTP automatic login, that is, do not use;. n etrc file;
-d use debug mode;
-G cancels the global file name.
http://blog.itpub.net/20943428/viewspace-630467/

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}*     

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.

Http://www.cnblogs.com/0201zcr/p/4737508.html



FTP timed Batch download file (Shell script and usage method) (GO)

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.