1

I'm struggling to execute commands through ssh, especially aliased command.

The alias I need is ldocker which is set in the remote .bashrc.

So far I tried:

$ssh bugs2 '. .bashrc && echo "--" && alias && echo "--"'

$ssh bugs2 'source .bashrc && echo "--" && alias && echo "--"'

$ssh bugs2 'bash "source .bashrc && alias"'
bash: source .bashrc && alias: Aucun fichier ou dossier de ce type

$ssh bugs2 "bash \"source .bashrc && alias\""
bash: source .bashrc && alias: Aucun fichier ou dossier de ce type

I've looked at the following posts

but could not find any solution to my issue.

So my question is:

How to execute, in a single line, .bashrc-remotely-aliased commands through ssh?

0

what about this :

ssh bugs2 "bash -ic remotealias"

for me it almost works, the alias is :

alias remotealias='echo 123123123'

and the output is :

bash: cannot set terminal process group (-1): Invalid argument
bash: no job control in this shell
123123123

EDIT: But stealing from here, the cleanest solution is to add the following line into the remote .bashrc file:

shopt -s expand_aliases
| improve this answer | |
  • 1
    Using ssh -t instead of ssh will remove the job control error – roaima Mar 10 '16 at 17:40
  • It almost worked for me too, ssh -t bugs2 'bash -ic ldocker info | head' outputs an error with docker, it just don't take the argument.. – Auzias Mar 11 '16 at 9:25

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.