0

This is either rather simple or impossible, however I can't seem to get a go with it. I'm trying to run a script located on a remote server and I have the following alias in my .bashrc:

alias fin='sh [email protected]:~/scripts/finder.sh'

I have set up SSH key authentication to that host, however I am getting the following error:

sh: 0: Can't [email protected]:~/scripts/finder.sh

Can someone please help, thanks :)

2
  • 1
    Duplicate? stackoverflow.com/questions/5162568/… Commented Nov 5, 2015 at 16:53
  • 1
    As an aside, classic sh does not support tilde expansion. Commented Nov 5, 2015 at 17:37

2 Answers 2

4

You cannot refer to a remote script as if it were a file name. You can use ssh but the syntax is slightly different.

ssh [email protected] scripts/finder.sh

As an aside, functions are often better than aliases.

fin () {
    ssh [email protected] scripts/finder.sh "$@"
}

The "$@" is for passing arguments. If the script takes no parameters, it can be omitted.

Sign up to request clarification or add additional context in comments.

1 Comment

Updated with an example.
1

alias fin='ssh [email protected] /home/username/scripts/finder.sh'

you need to make sure finder.sh has execute permissions and runs locally on host.co.uk as user username

3 Comments

The remote shell will run from the remote user's home directory; hard-coding the full path is redundant and involves some speculation here.
For me on mac in bash shell it was resolving to /Users/username/scripts/finder.sh
@sdayal, it bases that on a lookup on the actual user's home directory, so it'll be appropriate for the system at hand. /home/username is convention for traditional unix-family operating systems, so it's presumably such a system that the OP is SSHing to.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.