Solved

Linux, scp and sshpass

Posted on 2013-12-20
1
1,884 Views
Last Modified: 2013-12-20
I am using RHEL 6.5

If I perform the following command:

# sshpass -p 'xxxx' scp /etc/hosts root@xxclnt16:/home/hosts
#

Open in new window


It does not return an error, but the file is never actually copied.

I understand the problem is that the site was not authenticated, as I receive the following error if I do not use sshpass:

# scp /etc/hosts root@xxclnt16:/home/hosts                   
The authenticity of host 'xxclnt16 (10.14.1.18)' can't be established.
RSA key fingerprint is ef:e3:f8:71:cf:47:8b:1c:df:fa:82:ce:48:2a:66:92.
Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added 'xxclnt16,10.14.1.18' (RSA) to the list of known ho...

Open in new window


Why doesnt the command with sshpass report an error.  This would be quite helpful.  Is there any way to get it to report an error

Thanks
0
Comment
Question by:Los Angeles1
1 Comment
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
ID: 39732032
sshpass does not report error messages which go to the tty (the operation principle of sshpass is intercepting tty input/output), so you will not see any message (except for the "man-in-the middle" warning which does not go to the tty).

As far as I know the only way to deal with situations like yours is to inspect the returncode of sshpass.

Your particular problem should set a returncode of '6', so you could do

sshpass -p 'xxxx' scp /etc/hosts root@xxclnt16:/home/hosts

if [[ $? -eq 6 ]]; then
  echo "Host Key Unknown"
   # perform any desired action
fi


These are the returncodes of sshpass according to its manpage:
       
    1 Invalid command line argument
    2 Conflicting arguments given
    3 General runtime error
    4 Unrecognized response from ssh (parse error)
    5 Invalid/incorrect password
    6 Host public key is unknown. sshpass exits without confirming the new key.
The mentioned "man-in-the-middle" issue will produce a returncode of 255.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This is the error message I got (CODE) Error caused by incompatible libmp3lame 3.98-2 with ffmpeg I've googled this error message and found out sometimes it attaches this note "can be treated with downgrade libmp3lame to version 3.97 or 3.98" …
Network Interface Card (NIC) bonding, also known as link aggregation, NIC teaming and trunking, is an important concept to understand and implement in any environment where high availability is of concern. Using this feature, a server administrator …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now