Shell 请帮忙。我需要向这个多线程rsync脚本添加一个日志文件 定义源、目标、maxdepth和cd到源 设置最大并发rsync线程数 在再次检查rsync线程数之前需要等待多长时间 查找maxdepth级别内源目录中的所有文件夹 确保忽略父文件夹 带前导点斜线 创建目标文件夹并设置所有权和权限以匹配源 确保正在运行的rsync线程数低于阈值 在后台为当前子文件夹运行rsync,并将其中一个子文件夹移动到下一个子文件夹

Shell 请帮忙。我需要向这个多线程rsync脚本添加一个日志文件 定义源、目标、maxdepth和cd到源 设置最大并发rsync线程数 在再次检查rsync线程数之前需要等待多长时间 查找maxdepth级别内源目录中的所有文件夹 确保忽略父文件夹 带前导点斜线 创建目标文件夹并设置所有权和权限以匹配源 确保正在运行的rsync线程数低于阈值 在后台为当前子文件夹运行rsync,并将其中一个子文件夹移动到下一个子文件夹,shell,Shell,不确定这是否是您所追求的(我不知道rsync是什么),但您是否可以不只是以 ./myscript > logfile.log 或 (即:如果希望在输出过程中看到输出,请使用管道到T形三通) 或者。。。不确定这是真正的程序员所做的,但您可以将脚本中每个命令的输出附加到日志文件中,例如: #at the beginning define the logfile name: logname="logfile" #remove the file if it exists if [ -a ${lo

不确定这是否是您所追求的(我不知道rsync是什么),但您是否可以不只是以

./myscript > logfile.log

(即:如果希望在输出过程中看到输出,请使用管道到T形三通)

或者。。。不确定这是真正的程序员所做的,但您可以将脚本中每个命令的输出附加到日志文件中,例如:

#at the beginning define the logfile name:
logname="logfile"
#remove the file if it exists
if [ -a ${logfile}.log ]; then rm -i ${logfile}.log; fi
#for each command that you want to capture the output of, use >> $logfile
#eg:
mkdir -p "${target}/${subfolder}" >> ${logfile}.log
如果rsync有几个带名称的线程,我想您可以将日志文件存储为
>${logfile}${thread}.log
,并将末尾的文件连接成一个日志文件


希望有帮助?(我对回答问题还不熟悉-因此,如果我所发布的内容基本/不好,或者您已经考虑过这些想法,我表示歉意!)

感谢您的帮助。通过将-v开关添加到rsync,我解决了这个问题。

如果您愿意,我可以删除我的答案,希望它能作为一个未回答的主题吸引更多的观点。很遗憾听到它不起作用。。。分别重定向stdout和stderr有帮助吗?或者使用rsync特定的命令,比如第二篇文章?很抱歉,您不太了解rsync。您可能应该看看GNU
parallel
,以帮助了解“多线程”位(虽然它不是真正的多线程,而是多处理)。
 sleeptime=5
 find . -maxdepth ${depth} -type d | while read dir
    do
 if [ `echo "${dir}" | awk -F'/' '{print NF}'` -gt ${depth} ]
    then
 subfolder=$(echo "${dir}" | sed 's@^\./@@g')
    if [ ! -d "${target}/${subfolder}" ]
    then
mkdir -p "${target}/${subfolder}"
chown --reference="${source}/${subfolder}" "${target}/${subfolder}"
chmod --reference="${source}/${subfolder}" "${target}/${subfolder}"
    fi
while [ `ps -ef | grep -c [r]sync` -gt ${maxthreads} ]
do
echo "Sleeping ${sleeptime} seconds" 
sleep ${sleeptime}
done
nohup rsync -au "${source}/${subfolder}/" "${target}/${subfolder}/" 
    </dev/null >/dev/null 2>&1 &
    fi
    done
find . -maxdepth ${depth} -type f -print0 | rsync -au --files-from=- --from0 ./ "${target}/"
./myscript > logfile.log
./myscript | tee logfile.log
#at the beginning define the logfile name:
logname="logfile"
#remove the file if it exists
if [ -a ${logfile}.log ]; then rm -i ${logfile}.log; fi
#for each command that you want to capture the output of, use >> $logfile
#eg:
mkdir -p "${target}/${subfolder}" >> ${logfile}.log