How to enable sshpass output to console
Asked Answered
U

2

26

Using scp and interactively entering the password the file copy progress is sent to the console but there is no console output when using sshpass in a script to scp files.

$ sshpass -p [password] scp [file] root@[ip]:/[dir]

It seems sshpass is suppressing or hiding the console output of scp. Is there a way to enable the sshpass scp output to console?

Utterance answered 5/5, 2016 at 12:11 Comment(3)
I believe the best option is NOT to use sshpass. If you can, use pubkey authentication. If you need more freedom in control what is going on, you will have to write it as expect script, I guess.Arrio
This is an embedded target. sshpass is what is available for now.Utterance
Try out this link so that you may find [unix.stackexchange.com/questions/188291/…Sassoon
F
9

After

sudo apt-get install expect

the file send-files.exp works as desired:

#!/usr/bin/expect -f

spawn scp -r $FILES $DEST
match_max 100000
expect "*?assword:*"
send -- "12345\r"
expect eof
Filaria answered 20/4, 2018 at 15:47 Comment(0)
F
3

Not exactly what was desired, but better than silence:

SSHPASS="12345" sshpass -e  scp -v -r $FILES $DEST 2>&1 | grep -v debug1

Note that -e is considered a bit safer than -p.

Output:

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
Filaria answered 20/4, 2018 at 15:19 Comment(2)
why -e is considered a bit safer than -p?Thach
@Thach SSHPASS="12345" sshpass -e ps aux | grep sshpass shows sshpass -e ps aux while sshpass -p 12345 ps aux | grep sshpass shows sshpass -p zzzzz ps aux and there is a short period of time that ps may show -p 12345. In addition, there is history | grep shpass, but commands preceded by a space are not saved in history...Filaria

© 2022 - 2024 — McMap. All rights reserved.