Hi Team,

Last time in my email one space was missing and that lead to confusion I guess. I am very sorry for typo.

The cp command I tried to execute over ssh

----snip---
[user1@test ~]$ ssh user1@test       sh -c  'cp -vPprf /tmp/123 /tmp/4576'
user1@test's password:
cp: missing file arguments
Try `cp --help' for more information.
----snip---
last time by mistake I missed space between ssh user1@test and sh -c  'cp -vPprf /tmp/123 /tmp/4576'

but it's always failing. I have tried the same command on multiple Linux system and found same failure.


I dig into further following are the observations

---snip---
[user1@test ~]$ which cp
/bin/cp


[user1@test ~]$ cp --version
cp (GNU coreutils) 5.97

Copyright (C) 2006 Free Software Foundation, Inc.
This is free software.  You may redistribute copies of it under the terms of
the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.
There is NO WARRANTY, to the extent permitted by law.

Written by Torbjorn Granlund, David MacKenzie, and Jim Meyering.
---snip---

Then I execute
[user1@test ~]$ ssh user1@test sh -c  "'which cp; cp -vPprf /tmp/123 /tmp/4576'"
user1@test's password:
/usr/local/bin/cp
cp: Warning: the meaning of `-P' will change in the future to conform to POSIX.
Use `--parents' for the old meaning, and `--no-dereference' for the new one.
/tmp -> /tmp/4576/tmp
`/tmp/123' -> `/tmp/4576/tmp/123'


[user1@test ~]$ /usr/local/bin/cp --version
cp (fileutils) 4.1
Written by Torbjorn Granlund, David MacKenzie, and Jim Meyering.

Copyright (C) 2001 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


So from the above observation it's very clear the problem is while trying to execute cp command over ssh then it's taking /usr/local/bin/cp instead of
/bin/cp which is causing the problem.


But in PATH env variable /bin is preceding /usr/local/bin
[user1@test ~]$ echo $PATH
/usr/lib64/qt-3.3/bin:/usr/kerberos/bin:/bin:/usr/bin:/usr/dev_infra/platform/bin:/usr/dev_infra/generic/bin:/usr/local/bin:/usr/X11R6/bin:/usr/local/ade/bin:/scratch/user1/bin

Even I checked in over ssh in PATH /bin appearing before /usr/local/bin
[user1@test ~]$ ssh user1@test   sh -c  "'echo $PATH; which cp; cp -vPprf /tmp/123 /tmp/4576'"
user1@test's password:
/usr/lib64/qt-3.3/bin:/usr/kerberos/bin:/bin:/usr/bin:/usr/dev_infra/platform/bin:/usr/dev_infra/generic/bin:/usr/local/bin:/usr/X11R6/bin:/usr/local/ade/bin:/scratch/user1/bin
/usr/local/bin/cp

cp: Warning: the meaning of `-P' will change in the future to conform to POSIX.
Use `--parents' for the old meaning, and `--no-dereference' for the new one.


Can you please give me any pointer why over ssh cp command is taking /usr/local/bin specific executable rather than /bin specific executable?

Is there any way to force the cp command to take /bin specific executable over ssh?

Thanks in advance.

Best Regards,
Kousik