Linux shell script for delete old files from ftp

后端 未结 5 1589
醉梦人生
醉梦人生 2021-01-02 14:21

There is a problem - need to store the database backup on the FTP. On the FTP should not be more than 10 back-ups, ie, After you add backup to FTP should be removed, the old

5条回答
  •  我在风中等你
    2021-01-02 14:27

    It has passed several years, and while Graeme's answer helped me but I faced some problems with it and here is how to fix them.

    Sometimes the sentence like Trying aaaa:bbb:ccc:ffffdd::0... is at first line of listing varable. You have to remove it.

    rem="Trying aaaa:bbb:ccc:ffffdd::0...";
    rep="";
    listing=${listing/$rem/$rep}
    

    Also jsan commented he faced other issue: "value too great for base (error token is "08")" when $DD is 0x it is interpreted as x in octal (problem for 8 and 9)

    I faced same problem. So you better make sure there is no nun-numeric characters in $MM or $DD and then remove the 0 from beggining. Like 08 should become 8.

    so before looping on files, add this code:

    MM=$(tr -dc '0-9' <<< $MM)
    DD=$(tr -dc '0-9' <<< $DD)
    MM=${MM#0}
    DD=${DD#0}
    

    First two lines remove non-numeric characters and second last lines fix the problem with 08

提交回复
热议问题