如何取消缓冲并捕获LFTP EOF命令的输出?

huangapple go评论62阅读模式
英文:

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} &lt;&lt; EOF &gt; ${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 &quot;$REMOTEDIR&quot; &quot;$LOCALDIR&quot;
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 &quot;$(cat &lt;&lt;- EOF
	lftp $PROTOCOL://$URL -u ${USER},${PASS} &lt;&lt; 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 &quot;$REMOTEDIR&quot; &quot;$LOCALDIR&quot;
	quit
	EOFF
EOF
)&quot;

The env TERM=dumb is a random line I found that removes ANSI escape codes from the output to file.

huangapple
  • 本文由 发表于 2023年5月28日 21:50:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/76351812.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定