[英]shell/bash script to delete files from FTP directory older than 30 days
I need shell script to delete all files older than 30 days from FTP server directories.我需要 shell 脚本从 FTP 服务器目录中删除所有超过 30 天的文件。 I need to delete files from 5 different directories which are older than 30 days, should not delete the directories because they might have other files, have to delete only files older than 30 days.我需要从 5 个不同目录中删除超过 30 天的文件,不应该删除这些目录,因为它们可能有其他文件,只需要删除超过 30 天的文件。 This is the first time I am working on shell script.这是我第一次处理 shell 脚本。 tried following link no luck.尝试以下链接没有运气。 can anyone help me on this.谁可以帮我这个事。
FTP delete directories older than X days FTP 删除超过 X 天的目录
below is the code I am using in my.sh file but I am facing invalid command error下面是我在 my.sh 文件中使用的代码,但我面临无效命令错误
ftp -inv $HOST <<EOS
user $ftp_user $ftp_pass
find /path/somefolder/ -type f -iname '*' -mtime +30 -exec rm {} \;
quit
EOS
Need to check if file is older than 30 days if it is older delete it from the directory.如果文件较旧,则需要检查文件是否超过 30 天,将其从目录中删除。
Create a loop who checks every file and get the file creation date, if the file is older than 30 days delete this.创建一个检查每个文件并获取文件创建日期的循环,如果文件超过 30 天,请删除它。 If loop iterator is directory file count, check next path.如果循环迭代器是目录文件计数,请检查下一个路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.