How to best capture and log scp output?

前端 未结 9 1244
栀梦
栀梦 2020-12-31 01:55

I am trying to capture output from an install script (that uses scp) and log it. However, I am not getting everything that scp is printing out, namely, the progress bar. <

9条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-31 02:33

    I can't comment yet :( so I'll add an update here...

    @Martin had the best solution for me although if your scp command is midway through your script then it's output may appear after commands that actually ran afterwards.

    I think that is because script must run the command in a subshell but I am yet to test.

    EDIT: it does indeed spawn a shell so if you need things to run (and indeed fail) in a sequential manner (like in a build script) then you would have to add some logic around the use of the script command.

    i.e.

    script -q -c "your command" && sleep 1

    or something similar so that your parent shell waits for the child shell to finish before moving on.

提交回复
热议问题