1

I'd like to come up with a way to always source the user's profile and bash configuration files upon a interactive login or non-interactive login despite what file structure they may have. It would also be nice for it not to matter which flavor of Linux is installed on the machine.

For example, not everyone has a ~/.bashrc or ~/.bash_profile file, but if they do they should be sourced.

My initial thought would be something like this (this is being run programmatically after a ssh):

[ -r /etc/profile ] && . /etc/profile;[ -r ~/.bash_profile ] && . ~/.bash_profile;[ -r ~/.profile ] && . ~/.profile;[ -r ~/.bashrc ] && . ~/.bashrc; OTHER COMMANDS...

However, this isn't quite working as I planned. The functions from the .bashrc file do not seem to be loaded in.

I appreciate any help! Thanks.

Edit: Adding full SSH command

ssh -p 22 dev@123 '[ -r /etc/profile ] && source /etc/profile;[ -r ~/.bash_profile ] && source ~/.bash_profile;[ -r ~/.profile ] && source ~/.profile;[ -r ~/.bashrc ] && source ~/.bashrc;cd ~/apps/my-project/;npm install;bower install;grunt production;~/start-apps.sh;' In my case, the command 'grunt' isn't being found because it's initiated in the .bashrc file.
  • How is this being run? Is .bash_profile being run? – Barmar Jan 8 '15 at 22:22
  • SSH runs a login shell, so the profile files should be sourced anyway. – muru Jan 8 '15 at 22:22
  • @Barmar It's being run after the ssh. e.g. ssh dev@123 [ -r /etc/profile ] && . /etc/profile;[ -r ~/.bash_profile ] && . ~/.bash_profile;[ -r ~/.profile ] && . ~/.profile;[ -r ~/.bashrc ] && . ~/.bashrc; OTHER COMMANDS... – Jeff Howard Jan 8 '15 at 22:31
  • 1
    Is it in quotes? If not, everything after && will run on the client, not the server. Please update the question with the actual command. – Barmar Jan 8 '15 at 22:33
  • @Barmar ssh -p 22 dev@123 '[ -r /etc/profile ] && source /etc/profile;[ -r ~/.bash_profile ] && source ~/.bash_profile;[ -r ~/.profile ] && source ~/.profile;[ -r ~/.bashrc ] && source ~/.bashrc;cd ~/apps/my-project/;npm install;bower install;grunt production;~/start-apps.sh;' In my case, the command 'grunt' isn't being found because it's initiated in the .bashrc file. – Jeff Howard Jan 8 '15 at 23:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.