1

This command with a * in the find path works fine on the local server

Svr1$ find /path/*/foo/ -name "*20160208"

When I try this remotely from another server it doesn't work

Svr2$ echo $Pswd|ssh Svr1 /usr/local/bin/sudo -S find /path/*/foo/ -name "*20160208*"

The error message is:

find: stat() error /path/*/foo/: No such file or directory

However, if I change the search path to avoid using the * it works fine. Like this:

Svr2$ echo $Pswd|ssh Svr1 /usr/local/bin/sudo -S find /path/ -name "*20160208*"

What am I doing wrong? I think I need to quote or escape part of the string but I just cannot figure it out.

Many thanks.

2

The * is expanded by your local shell. You should quote your argument

ssh Svr1 /usr/local/bin/sudo -S find '/path/*/foo/' -name "20160208"
  • Precisely. The * never arrives at the remote computer. It has been expanded before you reach that stage. – Hennes Feb 9 '16 at 15:43
1

As @Matteo said, you need to escape the * from your local shell. He's done that in his first example:

ssh Svr1 /usr/local/bin/sudo -S find '/path/*/foo/' -name "20160208"

As alternative, either of these should work as well, as the single quotes ('...') and backslash (\) "hide" the * wildcard from your local shell:

ssh -t Svr1 /usr/local/bin/sudo 'find /path/*/foo/ -name *20160208'

or

ssh -t Svr1 /usr/local/bin/sudo find /path/\*/foo/ -name \*20160208

As a side note, see that I've included a -t argument to ssh so that sudo has a tty through which to ask for my password, which is MUCH better than putting the password on the command line, IMO. If you must pipe the sudo password in, I suggest doing it via cat secret.txt | find ..., which keeps the password out of the command line which is potentially visible to ps and to anyone with access to your shell history (including ~/.history and variants)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.