使用scp并以交互方式输入密码,文件复制进度将发送到控制台,但在脚本中使用sshpass来scp文件时没有控制台输出.
$ sshpass -p [password] scp [file] root@[ip]:/[dir]
Run Code Online (Sandbox Code Playgroud)
似乎sshpass正在抑制或隐藏scp的控制台输出.有没有办法启用sshpass scp输出到控制台?
后
sudo apt-get install expect
Run Code Online (Sandbox Code Playgroud)
该文件send-files.exp按需要工作:
#!/usr/bin/expect -f
spawn scp -r $FILES $DEST
match_max 100000
expect "*?assword:*"
send -- "12345\r"
expect eof
Run Code Online (Sandbox Code Playgroud)
不完全是所希望的,但比沉默更好:
SSHPASS="12345" sshpass -e scp -v -r $FILES $DEST 2>&1 | grep -v debug1
Run Code Online (Sandbox Code Playgroud)
请注意,这-e被认为比-p.
输出:
Executing: program /usr/bin/ssh host servername, user username, command scp -v -t /src/path/dst_file.txt
OpenSSH_6.6.1, OpenSSL 1.0.1i-fips 6 Aug 2014
Authenticated to servername ([10.11.12.13]:22).
Sending file modes: C0600 590493 src_file.txt
Sink: C0600 590493 src_file.txt
Transferred: sent 594696, received 2600 bytes, in 0.1 seconds
Bytes per second: sent 8920671.8, received 39001.0
Run Code Online (Sandbox Code Playgroud)