scp is giving no such file or directory

4/28/2018

The Linux I have in this container is as shown below:

root@sbolla-6c7b7589d8-5c2rb:/usr/safenet/lunaclient# uname -a
Linux sbolla-6c7b7589d8-5c2rb 3.10.0-693.5.2.el7.x86_64 #1 SMP Fri Oct 20 20:32:50 UTC 2017 x86_64 GNU/Linux
root@sbolla-6c7b7589d8-5c2rb:/usr/safenet/lunaclient#

I am trying to do a simple scp with sshpass command as shown below and running into this error. any ideas really appreciated. Please note that I have tried scp and not cp. Infact this line is in a script, I tried it on the linux command line I got this error. I have also tried escaping the Environment variables with ' and " and \ and all combos, but that doesn't seem to have helped.

root@sbolla-6c7b7589d8-5c2rb:/usr/safenet/lunaclient/bin# sshpass -p '$H_PASSWORD' scp -v  $H_USERNAME@$H_HOSTNAME:server.pem .
Executing: cp '--' 'admin@abc-def.brilliant.local' '.'
cp: cannot stat 'admin@abc-def.brilliant.local': No such file or directory
Executing: cp '--' ':server.pem' '.'
cp: cannot stat ':server.pem': No such file or directory
root@sbolla-6c7b7589d8-5c2rb:/usr/safenet/lunaclient/bin#

If I explicitly use this command i got it to work, not sure why. Please not that hostname in these outputs have been edited to some goofy names

root@sbolla-6c7b7589d8-5c2rb:/usr/safenet/lunaclient#   sshpass -p $HSM_PASSWORD scp admin@grs-defcon.brilliant.local:server.pem .

ls -lia 
root@sbolla-6c7b7589d8-5c2rb:/usr/safenet/lunaclient# ls -l | grep ser
-rw-r--r-- 1 root root 1172 Apr 28 12:23 server.pem
root@sbolla-6c7b7589d8-5c2rb:/usr/safenet/lunaclient# date
Sat Apr 28 12:24:29 UTC 2018
root@sbolla-6c7b7589d8-5c2rb:/usr/safenet/lunaclient#

I have tried the answer provided below but didn't work

sshpass -p "$H_PASSWORD" scp -v $H_USERNAME@${H_HOSTNAME}:server.pem .

another thing I have noticed is if I do the env on this container, I see an extra line in the environment variable , could that be an issue. See how this env shows. Note that I have not entered a line on purpose, when I type env command I see line next to the H_HOSTNAME and the H_PARTITION which is weird H_PARTITION=Operator

MYSQL_PORT=tcp://11.123.113.242:3306
LUNAHS=TRUE
H_HOSTNAME=grs-defcon.brilliant.local

ROOT_PORT_443_TCP_PORT=443
MYSQL_PORT_3306_TCP_ADDR=11.456.231.242
-- sbolla
kubernetes
scp
sh
sshpass

2 Answers

4/28/2018

Looks like 2 shell expansion issues. Try:

sshpass -p "$H_PASSWORD" scp -v $H_USERNAME@${H_HOSTNAME}:server.pem .
-- Janos Lenart
Source: StackOverflow

4/29/2018
# sshpass -p '$H_PASSWORD' scp -v  $H_USERNAME@$H_HOSTNAME:server.pem .
Executing: cp '--' 'admin@abc-def.brilliant.local' '.'
cp: cannot stat 'admin@abc-def.brilliant.local': No such file or directory
Executing: cp '--' ':server.pem' '.'

Your shell variable H_HOSTNAME has some white space at the end. It's causing the scp command to be something like this:

scp -v someuser@somehost :server.pem .

Scp interprets this to mean that two local files named someuser@somehost and :server.pem should be copied to the local directory .. It's trying to do a local-to-local copy for each file by invoking the cp program.

-- Kenster
Source: StackOverflow