英文:
How to unbuffer and capture output of LFTP EOF command?
问题
我有以下命令用于使用LFTP镜像一些文件:
unbuffer lftp $PROTOCOL://$URL -u ${USER},${PASS} << EOF >> ${LOGSTDOUT}
set dns:fatal-timeout never
set sftp:auto-confirm yes
set mirror:use-pget-n 50
set mirror:parallel-transfer-count 2
set mirror:parallel-directories yes
set mirror:include-regex $REGEX
set log:enabled/xfer yes
set log:file/xfer $LOG
set xfer:use-temp-file yes
set xfer:temp-file-name *.lftp
mirror -c -v --loop --Remove-source-dirs "$REMOTEDIR" "$LOCALDIR"
quit
EOF
我正在尝试捕获此命令的输出。我已经使用xfer输出到日志文件,但遗憾的是这不会显示我所需的进度百分比。
有什么想法吗?我的上述尝试使用unbuffer是不成功的。
英文:
I have the following command to mirror some files with LFTP:
unbuffer lftp $PROTOCOL://$URL -u ${USER},${PASS} << EOF > ${LOGSTDOUT}
set dns:fatal-timeout never
set sftp:auto-confirm yes
set mirror:use-pget-n 50
set mirror:parallel-transfer-count 2
set mirror:parallel-directories yes
set mirror:include-regex $REGEX
set log:enabled/xfer yes
set log:file/xfer $LOG
set xfer:use-temp-file yes
set xfer:temp-file-name *.lftp
mirror -c -v --loop --Remove-source-dirs "$REMOTEDIR" "$LOCALDIR"
quit
EOF
I am trying to capture the output of this command. I already output to a log file using xfer, but this sadly doesn't show the handy progress % that I desire.
Any thoughts? My above attempt with unbuffer is unsuccessful.
答案1
得分: 0
感谢@pjh的建议,我采用了以下使用script
的解决方案:
env TERM=dumb script -a $LOGSTDOUT -c "$(cat <<- EOF
lftp $PROTOCOL://$URL -u ${USER},${PASS} <<- EOFF
set dns:fatal-timeout never
set sftp:auto-confirm yes
set mirror:use-pget-n 50
set mirror:parallel-transfer-count 2
set mirror:parallel-directories yes
set mirror:include-regex $REGEX
set log:enabled/xfer yes
set log:file/xfer $LOG
set xfer:use-temp-file yes
set xfer:temp-file-name *.lftp
mirror -c -v --loop --Remove-source-dirs "$REMOTEDIR" "$LOCALDIR"
quit
EOFF
EOF
)"
英文:
Thanks to the suggestion of @pjh I have come to the following solution using script
:
env TERM=dumb script -a $LOGSTDOUT -c "$(cat <<- EOF
lftp $PROTOCOL://$URL -u ${USER},${PASS} << EOFF
set dns:fatal-timeout never
set sftp:auto-confirm yes
set mirror:use-pget-n 50
set mirror:parallel-transfer-count 2
set mirror:parallel-directories yes
set mirror:include-regex $REGEX
set log:enabled/xfer yes
set log:file/xfer $LOG
set xfer:use-temp-file yes
set xfer:temp-file-name *.lftp
mirror -c -v --loop --Remove-source-dirs "$REMOTEDIR" "$LOCALDIR"
quit
EOFF
EOF
)"
The env TERM=dumb
is a random line I found that removes ANSI escape codes from the output to file.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论