Requirements: FTP gets files for remote data, and downloads files according to the file's creation point in time. You can expand your own other requirements depending on the size of the file.
Summary of Knowledge points:
1, the time to obtain the file:
LS-LRT| awk ' {print $6 "" $7 "" $8} '
Time content:
SEP 8 16:03
2. Time format Conversion
Date " Sep 8 16:03 " +%y%m%d%h%m
Conversion Result:
201709081603
3. Specify file name, regular match
pattern="${month}.*.dat$"ls -lrt | awk ' $9 ~/ '$pattern'/{print $6 "" $7 "" $8}'
Notice that the pattern variable in awk is enclosed in ' ',. * is any character, and $ indicates a dat end. The content of pattern is set according to the requirement
4, compare the file time
ls-LRT |awk '$9 ~/'$pattern'/ {\Ctime="date-d \ ""$6" "$7" "$8"\ "+%y%m%d%h%m"; CTime|getline filetime;if(Filetime >'$checktime') Print $9; }
Gets the time of the file, converts the time, and then compares the converted time to the given $checktime, and displays the file name if it is larger than the $checkime time.
|getline Gets the result of the command execution for the execution command.
This completes the method of comparing the local file time. Next, determine the file time for the remote host.
5, FTP command log on to the remote host, and filter the contents of the file to be queried
Ftp_cmd () {ftp -i-n <<! Open $ftp _ipuser $get _user $get _pwdbinarycd ${get_dir}lcd ${local_dir}$*bye! }
Pattern= "${month}.*.dat$"
Files=$ (Ftp_cmdls-LRT |awk '$9 ~/'$pattern'/ {\
Ctime="date-d \ ""$6" "$7" "$8"\ "+%y%m%d%h%m"; \
CTime|getline filetime;if(Filetime >'$checktime') Print $9; }'|xargs)
Implement FTP to a specified host via a function call, CD to the specified directory, get LS-LRT results by awk, and then calculate the time to get the file name greater than the specified time.
6. Download the file
Ftp_cmd Mget $files
Linux Shell ftp command download file based on file date