1

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
  • 671
  • 3
  • 22
  • 39
  • Does the problem on!y occur when you use the `-v` option? – Mark Plotnick Apr 28 '18 at 13:54
  • I am trying without the -v option in the script and from the command line. I used that only for more debug info. So, the problem is happening with or without the -v option – sbolla Apr 28 '18 at 14:11
  • Looking at your environment - What is the output of `echo -n "$H_HOSTNAME" | cat -vet ` ? Maybe there's a CR or other whitespace at the end. – Mark Plotnick Apr 28 '18 at 14:57
  • it has an enter. see abc-defcon.brilliant.local$ – sbolla Apr 28 '18 at 18:47
  • See [How to determine where an environment variable came from](https://unix.stackexchange.com/questions/813/how-to-determine-where-an-environment-variable-came-from) if you need help to find where that extra newline is coming from. – Mark Plotnick Apr 29 '18 at 13:42

2 Answers2

2

Looks like 2 shell expansion issues. Try:

sshpass -p "$H_PASSWORD" scp -v $H_USERNAME@${H_HOSTNAME}:server.pem .
Janos Lenart
  • 25,074
  • 5
  • 73
  • 75
  • Unfortunately that didn't work either, root@sbolla-6c7b7589d8-5c2rb:~# sshpass -p "$HSM_PASSWORD" scp -v $HSM_USERNAME@${HSM_HOSTNAME}:server.pem . Executing: cp '--' 'admin@grs-defcon.brilliant.local' '.' cp: cannot stat 'admin@grs-defcon.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:~# – sbolla Apr 28 '18 at 13:44
  • 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 HSM_HOSTNAME and the HSM_PARTITION which is weird HSM_PARTITION=Operator MYSQL_PORT=tcp://11.123.113.242:3306 USE_LUNAHSM=TRUE HSM_HOSTNAME=grs-defcon.brilliant.local ROOT_PORT_443_TCP_PORT=443 MYSQL_PORT_3306_TCP_ADDR=11.456.231.242 – sbolla Apr 28 '18 at 13:48
1
# 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
  • 23,465
  • 21
  • 80
  • 106