Here's what I'm trying to do:
ssh andy@<ip_address> "cat .bash_aliases; sayhello"
Here's what happens:
alias sayhello="echo hello"
bash: sayhello: command not found
To be more specific about my problem I'm trying to invoke the command"sudo etherwake -i eth0 <mac_address>"
over ssh -- this executes (I think) on my local computer, giving a sudo: unable to resolve host [blabla]
error. It seems like any commands that are not standard bash commands are parsed by my local machine.
If that's what's happening, how do I get around it? If not, what is the explanation?
In general this is not a good idea to use aliases in scripts.
Yet I can suggest one way to do it, but bare in mind how unsafe it is.
eval
, Here we go.
ssh remote_host "shopt -s expand_aliases ; source ~/.bash_aliases ; eval sayhello"
By default alias expansion is enabled only for interactive shells. To turn it on use shopt -s
command.
You will need to source the aliases into your shell context anyway.
Now you are set to use your aliases via the eval
command.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With