Solved Using scp and tcsh generates a "Then/ending not found"

ssbear

Member

Reaction score: 2
Messages: 31

Hi FreeBSD community!

I have a little minor trouble with tcsh since years. Each time I execute a scp, my shell print an error. Here's an example:
Code:
test@eochla:~ % scp .shrc user@domain:
then: then/endif not found.
.shrc                                                   100%  694     2.5MB/s   00:00

The error is the then: then/endif not found. However, it does not block the command.
Do you have an idea about the origin? I use tcsh, and it seems to be related to...

Here are some of my files. As you can see, eveything seems to be by default. Maybe I forgot a configuration file?
I precise I have the same issue on my MacBook, using tcsh.

Any help or advices would be helpfull!

.cshrc
Code:
# $FreeBSD$
#
# .cshrc - csh resource script, read at beginning of execution by each shell
#
# see also csh(1), environ(7).
# more examples available at /usr/share/examples/csh/
#

alias h         history 25
alias j         jobs -l
alias la        ls -aF
alias lf        ls -FA
alias ll        ls -lAF

# These are normally set through /etc/login.conf.  You may override them here
# if wanted.
# set path = (/sbin /bin /usr/sbin /usr/bin /usr/local/sbin /usr/local/bin $HOME/bin)
# A righteous umask
# umask 22

setenv  EDITOR  vi
setenv  PAGER   less

if ($?prompt) then
        # An interactive shell -- set some stuff up
        set prompt = "%N@%m:%~ %# "
        set promptchars = "%#"

        set filec
        set history = 1000
        set savehist = (1000 merge)
        set autolist = ambiguous
        # Use history to aid expansion
        set autoexpand
        set autorehash
        set mail = (/var/mail/$USER)
        if ( $?tcsh ) then
                bindkey "^W" backward-delete-word
                bindkey -k up history-search-backward
                bindkey -k down history-search-forward
        endif

endif

.profile
Code:
# $FreeBSD$
#
# .profile - Bourne Shell startup script for login shells
#
# see also sh(1), environ(7).
#

# These are normally set through /etc/login.conf.  You may override them here
# if wanted.
# PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:$HOME/bin; export PATH

# Setting TERM is normally done through /etc/ttys.  Do only override
# if you're sure that you'll never log in via telnet or xterm or a
# serial line.
# TERM=xterm;   export TERM

EDITOR=vi;      export EDITOR
PAGER=less;     export PAGER

# set ENV to a file invoked each time sh is started for interactive use.
ENV=$HOME/.shrc; export ENV

# Let sh(1) know it's at home, despite /home being a symlink.
if [ "$PWD" != "$HOME" ] && [ "$PWD" -ef "$HOME" ] ; then cd ; fi

# Query terminal size; useful for serial lines.
if [ -x /usr/bin/resizewin ] ; then /usr/bin/resizewin -z ; fi

# Display a random cookie on each login.
if [ -x /usr/bin/fortune ] ; then /usr/bin/fortune freebsd-tips ; fi

.shrc
Code:
# $FreeBSD$
#
# .shrc - bourne shell startup file
#
# This file will be used if the shell is invoked for interactive use and
# the environment variable ENV is set to this file.
#
# see also sh(1), environ(7).
#


# file permissions: rwxr-xr-x
#
# umask 022

# Uncomment this to enable the builtin vi(1) command line editor in sh(1),
# e.g. ESC to go into visual mode.
# set -o vi


# some useful aliases
alias h='fc -l'
alias j=jobs
alias m="$PAGER"
alias ll='ls -laFo'
alias l='ls -l'
alias g='egrep -i'
 
# # be paranoid
# alias cp='cp -ip'
# alias mv='mv -i'
# alias rm='rm -i'


# set prompt: ``username@hostname:directory $ ''
PS1="\u@\h:\w \\$ "

# search path for cd(1)
# CDPATH=:$HOME

.login
Code:
# $FreeBSD$
#
# .login - csh login script, read by login shell, after `.cshrc' at login.
#
# See also csh(1), environ(7).
#

# Query terminal size; useful for serial lines.
if ( -x /usr/bin/resizewin ) /usr/bin/resizewin -z

# Display a random cookie on each login.
if ( -x /usr/bin/fortune ) /usr/bin/fortune freebsd-tips

/etc/csh.cshrc
Code:
# $FreeBSD: releng/12.2/bin/csh/csh.cshrc 337849 2018-08-15 14:41:24Z brd $
#
# System-wide .cshrc file for csh(1).

/etc/csh.csh.login
Code:
# $FreeBSD: releng/12.2/bin/csh/csh.cshrc 337849 2018-08-15 14:41:24Z brd $
#
# System-wide .cshrc file for csh(1).
test@eochla:~ % cat /etc/csh.login
# $FreeBSD: releng/12.2/bin/csh/csh.login 363525 2020-07-25 11:57:39Z pstef $
#
# System-wide .login file for csh(1).
#
# For the setting of languages and character sets please see
# login.conf(5) and in particular the charset and lang options.
# For full locales list check /usr/share/locale/*
#
# Check system messages
# msgs -q
# Allow terminal messages
# mesg y

/etc/profile
Code:
# $FreeBSD: releng/12.2/bin/sh/profile 363525 2020-07-25 11:57:39Z pstef $
#
# System-wide .profile file for sh(1).
#
# For the setting of languages and character sets please see
# login.conf(5) and in particular the charset and lang options.
# For full locales list check /usr/share/locale/*
# You should also read the setlocale(3) man page for information
# on how to achieve more precise control of locale settings.
#
# Check system messages
# msgs -q
# Allow terminal messages
# mesg y


Regards,
 

SirDice

Administrator
Staff member
Administrator
Moderator

Reaction score: 13,892
Messages: 40,606

What does alias output?
 
OP
ssbear

ssbear

Member

Reaction score: 2
Messages: 31

I made all those tests with a new user (so, with everything on default, except if I forgot something...)
Code:
h       (history 25)
j       (jobs -l)
la      (ls -aF)
lf      (ls -FA)
ll      (ls -lAF)

Regards,
 

SirDice

Administrator
Staff member
Administrator
Moderator

Reaction score: 13,892
Messages: 40,606

Your files all seem to be in order, aliases looks good too. Do you get this only with scp(1) or do some other commands give the same error?
 
OP
ssbear

ssbear

Member

Reaction score: 2
Messages: 31

For what I remember, this error only occured when I use scp.

Regards,
 

SirDice

Administrator
Staff member
Administrator
Moderator

Reaction score: 13,892
Messages: 40,606

Is there anything configured in ~/.ssh/config? I find it rather strange you have the exact same issue on a Mac.
 
OP
ssbear

ssbear

Member

Reaction score: 2
Messages: 31

Nope, this user does not have any ~/.ssh/. More, the default one from /etc/ssh/ssh_config is fully commented.

Hum... probably not related to tcsh, because I got this issue to with sh:
Code:
test@domain:~ % scp .shrc user@domain:
then: then/endif not found.
.shrc                                                   100%  694     2.5MB/s   00:00   
test@domain:~ % sh
$ scp .shrc user@domain:
then: then/endif not found.
.shrc                                                   100%  694     2.3MB/s   00:00

Regards
 

SirDice

Administrator
Staff member
Administrator
Moderator

Reaction score: 13,892
Messages: 40,606

I'm wondering if your /usr/bin/scp is the actual executable. What does file /usr/bin/scp output? Oh, and for good measure echo $PATH.
 
OP
ssbear

ssbear

Member

Reaction score: 2
Messages: 31

Once again, it seems to be normal:
Code:
user@domain / $  file /usr/bin/scp
/usr/bin/scp: ELF 64-bit LSB executable, x86-64, version 1 (FreeBSD), dynamically linked, interpreter /libexec/ld-elf.so.1, for FreeBSD 12.2, FreeBSD-style, stripped


And regarding the echo $PATH:
Code:
/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/home/user/bin

Regards,
 

SirDice

Administrator
Staff member
Administrator
Moderator

Reaction score: 13,892
Messages: 40,606

Do you get the same error if you use /usr/bin/scp .shrc user@domain:? If you don't get the error there then there might be something in your PATH that takes precedence.
 

SirDice

Administrator
Staff member
Administrator
Moderator

Reaction score: 13,892
Messages: 40,606

Oh, it might be something on the 'other' side so to speak. Not a local issue but something configured for that 'test' user on the destination host.
 
OP
ssbear

ssbear

Member

Reaction score: 2
Messages: 31

Hum... it seems you found a beggining of something ! Indeed, when I do:
scp myfile anotheruser@domain:
I got the issue.

Whith a:
scp myfile domain:
In other words, without changing the user, I do not have it anymore.

So, if I understand well, I have to use a su, and then, launch the command, instead changing the user directly with scp. But, before understand why (and I'm interested), this solution does not fit to me. The user on the remote machine does not exist on the local machine, so I can't switch user before.


Regards,
 

SirDice

Administrator
Staff member
Administrator
Moderator

Reaction score: 13,892
Messages: 40,606

No, just login on that destination host and check the shell login files for the users there.

Doing a scp localfile someuser@destination: doesn't change your user on the local machine. It just means you're logging in as 'someuser' on the 'destination' host. The issue appears to be on that 'destination' host, that's why you're getting the same error on your Mac too.
 

ralphbsz

Son of Beastie

Reaction score: 2,680
Messages: 3,543

I'm not at all a tcsh expert (haven't used it in ~15 years), but I suspect that somewhere in one of the setup files (like .cshrc) that tcsh runs upon login, there is a syntax error, but one that only matters when running in the somewhat unusual environment of a scp login. I'm going to bet that the syntax error has to do with an if statement. And here is a potential candidate for that syntax error:

.cshrc
Code:
if ($?prompt) then
...
        if ( $?tcsh ) then
...
See how one of the if statements has spaces between the parenthese and the thing being tested, the other doesn't? I suspect that only one of them is correct, but I don't know which one. I don't know about (t)csh, but in (ba)sh, those spaces are often needed, otherwise the parser will lump everything together (there are exceptions, such as assignment statements: "pi=3" is correct, while "pi = 3" won't work). Try adding or removing the.

And debugging suggestion: One at a time, replace all the setup files (like .cshrc) with empty files on the destination machine, and see whether the error goes away.
 
OP
ssbear

ssbear

Member

Reaction score: 2
Messages: 31

Hi. Sorry for the delay.
And you're right: on the remote machine, the user recreates his own .cshrc, and the error has disappeared. I don't have the old file anymore, so I can't check precisely where were the fault.

Thanks a lot for your time and your support!


Regards,
 
Top