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

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

How to unbuffer and capture output of LFTP EOF command?

问题

我有以下命令用于使用LFTP镜像一些文件:

  1. unbuffer lftp $PROTOCOL://$URL -u ${USER},${PASS} << EOF >> ${LOGSTDOUT}
  2. set dns:fatal-timeout never
  3. set sftp:auto-confirm yes
  4. set mirror:use-pget-n 50
  5. set mirror:parallel-transfer-count 2
  6. set mirror:parallel-directories yes
  7. set mirror:include-regex $REGEX
  8. set log:enabled/xfer yes
  9. set log:file/xfer $LOG
  10. set xfer:use-temp-file yes
  11. set xfer:temp-file-name *.lftp
  12. mirror -c -v --loop --Remove-source-dirs "$REMOTEDIR" "$LOCALDIR"
  13. quit
  14. EOF

我正在尝试捕获此命令的输出。我已经使用xfer输出到日志文件,但遗憾的是这不会显示我所需的进度百分比。

有什么想法吗?我的上述尝试使用unbuffer是不成功的。

英文:

I have the following command to mirror some files with LFTP:

  1. unbuffer lftp $PROTOCOL://$URL -u ${USER},${PASS} &lt;&lt; EOF &gt; ${LOGSTDOUT}
  2. set dns:fatal-timeout never
  3. set sftp:auto-confirm yes
  4. set mirror:use-pget-n 50
  5. set mirror:parallel-transfer-count 2
  6. set mirror:parallel-directories yes
  7. set mirror:include-regex $REGEX
  8. set log:enabled/xfer yes
  9. set log:file/xfer $LOG
  10. set xfer:use-temp-file yes
  11. set xfer:temp-file-name *.lftp
  12. mirror -c -v --loop --Remove-source-dirs &quot;$REMOTEDIR&quot; &quot;$LOCALDIR&quot;
  13. quit
  14. 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的解决方案:

  1. env TERM=dumb script -a $LOGSTDOUT -c "$(cat <<- EOF
  2. lftp $PROTOCOL://$URL -u ${USER},${PASS} <<- EOFF
  3. set dns:fatal-timeout never
  4. set sftp:auto-confirm yes
  5. set mirror:use-pget-n 50
  6. set mirror:parallel-transfer-count 2
  7. set mirror:parallel-directories yes
  8. set mirror:include-regex $REGEX
  9. set log:enabled/xfer yes
  10. set log:file/xfer $LOG
  11. set xfer:use-temp-file yes
  12. set xfer:temp-file-name *.lftp
  13. mirror -c -v --loop --Remove-source-dirs "$REMOTEDIR" "$LOCALDIR"
  14. quit
  15. EOFF
  16. EOF
  17. )"
英文:

Thanks to the suggestion of @pjh I have come to the following solution using script:

  1. env TERM=dumb script -a $LOGSTDOUT -c &quot;$(cat &lt;&lt;- EOF
  2. lftp $PROTOCOL://$URL -u ${USER},${PASS} &lt;&lt; EOFF
  3. set dns:fatal-timeout never
  4. set sftp:auto-confirm yes
  5. set mirror:use-pget-n 50
  6. set mirror:parallel-transfer-count 2
  7. set mirror:parallel-directories yes
  8. set mirror:include-regex $REGEX
  9. set log:enabled/xfer yes
  10. set log:file/xfer $LOG
  11. set xfer:use-temp-file yes
  12. set xfer:temp-file-name *.lftp
  13. mirror -c -v --loop --Remove-source-dirs &quot;$REMOTEDIR&quot; &quot;$LOCALDIR&quot;
  14. quit
  15. EOFF
  16. EOF
  17. )&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:

确定