I can't get this command to work:
user@server:~: ssh otherserver bash -ic 'source .profile; some-aliased-command'
Variations I tried
user@server:~: ssh -t otherserver bash -ic 'source .profile; some-aliased-command'
user@server:~: ssh -t otherserver "bash -ic 'source .profile; some-aliased-command'"
user@server:~: ssh -t otherserver "bash -ic source .profile; some-aliased-command"
user@server:~: ssh otherserver bash -ic 'source .profile; some-aliased-command'
user@server:~: ssh otherserver "bash -ic 'source .profile; some-aliased-command'"
user@server:~: ssh otherserver "bash -ic source .profile; some-aliased-command"
I usually get a variation of these errors:
bash: cannot set terminal process group (-1): Invalid argument
bash: no job control in this shell
stdin: is not a tty
bash: some-aliased-command: command not found
But like this, it does work:
user@server:~: ssh otherserver bash -i << EOF
source .profile
some-aliased-command
EOF
In fact when I run this:
ssh -t otherserver 'bash -ic "source ~/.profile; alias"'
It lists all the aliases including the some-aliased-command that I want to run.
I tried al sorts of variations with single, double, escaped quoutes, but I am stuck and it will only work with the heredoc version.
How do I make it work without the heredoc ( as a one-liner ) ?
.profilecontains commands that require a tty. Why are you sourcing.profilein the first place?.profile. Aliases are local to the shell and.profileis only sourced by login shells. So most shells would not have any access to those aliases. If you have aliases in.profile, then you are doing it wrong.ssh -t otherserver 'bash -ic "source ~/.profile; alias"'or use the heredoc syntax ? How is it different ?