gpt4 book ai didi

BASH递归查找文件名并复制到ftp

转载 作者:行者123 更新时间:2023-11-29 09:49:24 27 4
gpt4 key购买 nike

我正在编写一个 Bash 脚本(见下文),该脚本递归地在 SAN 上的目录中搜索具有特定文件名且更新时间超过 4 小时的文件。然后将所有这些文件复制到特定的 FTP 位置,并通过电子邮件通知复制已完成。该脚本工作正常,只是它只复制顶级目录中的文件。我在较低目录中遇到的错误是:

#
remote: -v
ftp: local: -v: No such file or directory
local: ./Test01/test02/folder02_01_1200_m30.mp4 remote: ./Test01/test02/folder02_01_1200_m30.mp4
229 Entering Extended Passive Mode (|||45127|)
550 ./Test01/test02/folder02_01_1200_m30.mp4: File does not exist. (2)
221 Goodbye.
#

这是脚本

#!/bin/bash
#The location from where the script should search
GSPORIGIN='/Volumes/folder01/folder02'

#File Names to be moved
FILE1='*1200_m30.mp4'

#FTP Details
HOST='xxxx.upload.com'
USER='xxxxxxx'
PASSWD='xxxxxxxxxxxx'
#the destination directory on the FTP
DESTDIR="/8619/_!/TEST"


# Go to the location from where the search should start
cd $GSPORIGIN
for file in `find . -type f -name "*1200_m30.mp4" -mmin -240`
do
echo $file
if [ -f $file ] ; then
ftp -n -v $HOST << EOT
ascii
user $USER $PASSWD
prompt
cd $DESTDIR
mput -v $file
EOT
echo "$file has been copied to FTP" | mail -s "$file has been copied to FTP in Directory $DESTDIR" xxx.xxx@xxx.com;
else exit 1
fi
done

最佳答案

要执行您正在执行的操作,您必须在目标 FTP 上重新创建目录。使用 basename/dirname 命令和 mkdir 命令,如下所示:

for file in `find . -type f -name "*1200_m30.mp4" -mmin -240`
do
echo $file
if [ -f $file ] ; then

destdirname=`dirname "$file"`

ftp -n -v $HOST << EOT
ascii
user $USER $PASSWD
prompt
cd $DESTDIR
mkdir $destdirname
mput -v $file
EOT
echo "$file has been copied to FTP" | mail -s "$file has been copied to FTP in Directory $DESTDIR" xxx.xxx@xxx.com;
else exit 1
fi

关于BASH递归查找文件名并复制到ftp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6445229/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com