bash - How to check on FTP if there files on the list older than 7 days -
I have a list of files from a remote FTP server:
drwxrwxrwx 2 test backup All 4096 July 8 02:30. Drwxrwxrwx 5 0 0 4096 Jul 23 07:02 .. -rw-rw-rw-1 test backup everyone 352,696 July 18 02:30 expdp_teST11P2_custom_Fri.dmp.gz -rw-rw-rw-1 test backup everyone aged 352796 02:30 expdp_teST11P2_custom_Mon.dmp.gz -rw-rw-rw-1 test backup everyone 352,615 July 19 02:30 expdp_teST11P2_custom_Sat.dmp.gz -rw-rw-rw-1 test backup everyone 352,626 July 20 02:30 expdp_teST11P2_custom_Sun .dmp.gz -rw-rw-rw-1 test backup everyone 10511523642 July 24 03:08 expdp_teST11P2_custom_Thu.dmp.gz -rw-rw-rw-1 test backup everyone 9 96881744 22 03:03 expdp_teST11P2_custom_Tue.dmp.gz -rw-rw-rw-1 test backup everyone 10504557 9th Jul 23 03:03 expdp_teST11P2_custom_Wed.dmp.gz I have to check if there are 7 days of any age than any file, you have any ideas I need How can I do this in Bash?
As I understand this issue, you have ftp (and You do not have access to find on the remote server). Assuming that you have a directory list in the file named ftptimes , you can identify files older than 7 days: $ awk -v cutoff = "$ (Date -d "7 days ago" +% s) "'{line = $ 0; "Date-D \" "$ 6" "$ 7" "$ 8" \ "+% s" | Gateline; Fdate = $ 1} fdate & lt; Cutoff {print line} 'ftptimes From the date of your sample, the output will be:
drwxrwxrwx 2 test-backup every 4096 July 8 02:30. awk by doing the parts of the command one by one: -
-vCatoff = "$ (date -D "7 days ago" +% s) "
This defines the awk with the name cutoff , in which the time of Unix would be 1970- 01-01 00:00:00 UTC) 7 days ago -
line = $ 0; It later saves the current input line for use in the variable line . -
"date -d \" "$ 6" "$ 7" $ 8 "\" +% s "| geteline; fdate = $ 1 This unix changes the date given by FTP in the timeline, reads at that time, and a variable called saves it in fdate . fdate If the file date is less than the cutoff date, the line is printed.
Sample data that you have provided, the only file that's more than seven days old is the current directory (. ) which is 8th July For example, if we want the file more than 5 days old , then more files will be printed: $ Awk -v cutoff = "$ (date -d)" $ 5 "" $ 8 " +% S "| Getline; Fdate = $ 1} fdate & lt; cutoff {print line} 'ftptimes drwxrwxrwx 2 test-backup every 4096 July 8 02:30. -rw-rw-rw-1 test backup everyone aggregates 352,696 18 02:30 expdp_teST11P2_custom_Fri.dmp.gz -rw-rw-rw-1 test backup everyone 352,615 July 19 02:30 expdp_teST11P2_custom_Sat.dmp.gz above In the meantime, I assumed that information from the FTP was stored in the file. It is also possible to pipe in:
echo ls. FTP host port | Awk -v cutoff = "$ (date -d" 5 days ago "+% s)" '{line = $ 0; "Date-D \" "$ 6" "$ 7" "$ 8" \ "+% s" | Gateline; Fdate = $ 1} fdate & lt; Cutoff {print line} ' Where host and ports are replaced by your server host and port. Bash version
The above can also be completed in bash , although it requires explicit looping. Then, assuming FTP information in the file $ cutoff = "$ (date -d" 7 days ago "+% s)"; While reading the line; Determine - $ line; Fdate = $ (date -d "$ 6 $ 7 $ 8" +% s); [$ Fdate -lt $ cutoff] & amp; Amp; Echo $ line; Did & lt; Ftptimes drwxrwxrwx 2 test-backup each 4096 July 8 02:30.
Comments
Post a Comment