3

My simple file scp from a remote host (actually a locally run VM but that shouldn't matter) failed without displaying any error message but clearly not having copied the desired file:

scp myuser@myhost:~/.bashrc ~/.bashrc.ubuntu

The only thing it displayed was

================================================================================

I thought that was peculiar because that was the first line displayed in my login greeting on the remote, which looks like:

================================================================================
Welcome to <Ubuntu 12.04.2 LTS>
You are <myuser> logged into <hostname> (my_ipaddress)
Today is <Wed Aug 28 16:48:49 EDT 2013>
================================================================================

And here are the contents of the .bashrc on the remote that define that greeting:

1 if [ -f ~/.bash_aliases ]; then
2     . ~/.bash_aliases
3 fi
4 
5 
6 export PS1='\w@\t>'
7 
8 set -o vi
9 
10 printf %80s |tr " " "="
11 echo
12 
13 echo "Welcome to <"`lsb_release -d | sed 's/Description\:\s*//'`">"
14 
15 export IPADDR=`hostname -I`
16 
17 echo "You are <"$LOGNAME"> logged into <"$HOSTNAME"> ("$IPADDR")"
18 
19 echo "Today is <"`date`">"
20 
21 
22 printf %80s |tr " " "="
23 echo

Once I removed everything from like 9 down on the remote .bashrc, the scp succeeded.

Can anyone expound on this peculiar occurrence? The local host is Mac OS Mountain Lion and the remote (VM) is Ubuntu 12.04.

amphibient
  • 12,472
  • 18
  • 64
  • 88

2 Answers2

7

Helped by this thread, I figured that the special characters in the greeting were the problem and that the .bashrc should just return unless we are in the interactive mode. So I added the following to the beginning of .bashrc on the remote:

# If not running interactively, don't do anything
if [[ $- != *i* ]]; then return; fi

Which solved the problem and I was able to use scp

amphibient
  • 12,472
  • 18
  • 64
  • 88
1

yes, if your remote shell is chatty when you ssh, scp will fail as it depends on a clear ssh connection. here is a more detailed explanation.

https://blogs.oracle.com/janp/entry/how_the_scp_protocol_works

johnshen64
  • 516
  • 2
  • 4