Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I would like to remotely execute a .bash_profile alias, but I cannot find the proper command.

I tried:
ssh user@host "bash -ic myalias"
but it doesn't work

I get:

bash: cannot set terminal process group (-1): Invalid argument  
bash: no job control in this shell  
bash: myalias: command not found
share|improve this question
    
You get myalias: command not found. Have you made the alias!? –  Pazis Nov 18 '13 at 17:11
    
@Pazis, the alias exists in .bash_profile –  Daniele B Nov 18 '13 at 17:26

2 Answers 2

You could put the alias in a separate file. Then you would source it from your .bash_profile and the ssh command would look like:

ssh user@host bash -c '. .bash_aliases; shopt -s expand_aliases; myalias'
share|improve this answer
    
And the reason why the profile isn't read in the first place is that, as the man page says, "If command is specified, it is executed on the remote host instead of a login shell. –  Jenny D Dec 10 '13 at 9:12

I think you should try putting the alias command in .bashrc instead of .bash_profile.

I tried this on one of my servers and the alias was recognized.

I believe that it is because ssh user@host is a non-login shell. Usually .bash_profile is skipped for non-login shells.

share|improve this answer
1  
There may be a line near the top of the .bash_profile script which stops execution for non-interactive shells. –  fredden Dec 10 '13 at 5:54
    
This will not help. As the man page says, "If command is specified, it is executed on the remote host instead of a login shell". It has nothing at all to do with the .bashrc since it never gets called since the login shell doesn't get called. –  Jenny D Dec 10 '13 at 9:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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