If you do: ssh MACHINE command bash is run in non-interactive mode, but detects it was started by a RSH/SSH, and only sources a single startup file: ~/.bashrc I'd like a way for it to ALSO load a global profile, to provide some environment for users. This is a real pain trying to run for i in $MACHINES ; do ssh $i emerge ... ; done ; as /etc/profile.env is never loaded so PATH/CONFIG_PROTECT and other things don't contain important information. Looking at the bash source, it LOOKS like /etc/bash/bashrc should be loaded for non-interactive shells, but I'm not sure why it isn't. Reproducible: Always Steps to Reproduce: 1. 2. 3. head ~ # ssh node009 node009 ~ # emerge info Portage 2.0.51.22-r2 (default-linux/x86/2005.0, gcc-3.4.4, glibc-2.3.5-r0, 2.6.12-gentoo-r4 i686) ================================================================= System uname: 2.6.12-gentoo-r4 i686 Intel(R) Pentium(R) 4 CPU 3.00GHz Gentoo Base System version 1.12.0_pre1 distcc 2.18.3 i686-pc-linux-gnu (protocols 1 and 2) (default port 3632) [disabled] ccache version 2.4 [enabled] dev-lang/python: 2.3.4-r1, 2.4.1-r1 sys-apps/sandbox: 1.2.11 sys-devel/autoconf: 2.13, 2.59-r7 sys-devel/automake: 1.4_p6, 1.5, 1.6.3, 1.7.9-r1, 1.8.5-r3, 1.9.6 sys-devel/binutils: 2.16.1 sys-devel/libtool: 1.5.18-r1 virtual/os-headers: 2.6.11-r2 ACCEPT_KEYWORDS="x86 ~x86" AUTOCLEAN="yes" CBUILD="i686-pc-linux-gnu" CFLAGS="-march=pentium4 -O2 -pipe" CHOST="i686-pc-linux-gnu" CONFIG_PROTECT="/etc /usr/kde/2/share/config /usr/kde/3/share/config /usr/share/ config /usr/spool/PBS /var/qmail/control" CONFIG_PROTECT_MASK="/etc/gconf /etc/terminfo /etc/env.d" CXXFLAGS="-march=pentium4 -O2 -pipe" DISTDIR="/mnt/distfiles" FEATURES="autoaddcvs autoconfig buildpkg ccache distlocks sandbox sfperms" GENTOO_MIRRORS="http://distfiles.gentoo.org http://distro.ibiblio.org/pub/Linux/distributions/gentoo" MAKEOPTS="-j4" PKGDIR="/mnt/packages/node/nodebug" PORTAGE_TMPDIR="/scratch/gentoo-portage-tmp" PORTDIR="/usr/portage" SYNC="rsync://mirror.iat.sfu.ca/gentoo-portage" USE="x86 aalib acl alsa berkdb crypt cscope erandom f77 fam floppyboot fortran gcj gdbm hpn ipv6 java jikes jpeg kerberos krb5 ldap libwww mmx ncurses netboot objc pam pbs pcap perl pic png python quota quotas readline rpc sasl slang slp snmp spell sse ssh ssl tcpd urandom userlocales xfs xml xml2 zlib userland_GNU kernel_linux elibc_glibc" Unset: ASFLAGS, CTARGET, LANG, LC_ALL, LDFLAGS, LINGUAS, PORTDIR_OVERLAY head ~ # ssh node009 emerge info Gentoo Base System version 1.12.0_pre1 Portage 2.0.51.22-r2 (default-linux/x86/2005.0, gcc-3.4.4, glibc-2.3.5-r0, 2.6.12-gentoo-r4 i686) ================================================================= System uname: 2.6.12-gentoo-r4 i686 Intel(R) Pentium(R) 4 CPU 3.00GHz distcc 2.18.3 i686-pc-linux-gnu (protocols 1 and 2) (default port 3632) [disabled] ccache version 2.4 [enabled] dev-lang/python: 2.3.4-r1, 2.4.1-r1 sys-apps/sandbox: 1.2.11 sys-devel/autoconf: 2.13, 2.59-r7 sys-devel/automake: 1.4_p6, 1.5, 1.6.3, 1.7.9-r1, 1.8.5-r3, 1.9.6 sys-devel/binutils: 2.16.1 sys-devel/libtool: 1.5.18-r1 virtual/os-headers: 2.6.11-r2 ACCEPT_KEYWORDS="x86 ~x86" AUTOCLEAN="yes" CBUILD="i686-pc-linux-gnu" CFLAGS="-march=pentium4 -O2 -pipe" CHOST="i686-pc-linux-gnu" CONFIG_PROTECT="/etc /usr/kde/2/share/config /usr/kde/3/share/config /usr/share/ config /var/qmail/control" CONFIG_PROTECT_MASK="/etc/gconf /etc/env.d" CXXFLAGS="-march=pentium4 -O2 -pipe" DISTDIR="/mnt/distfiles" FEATURES="autoaddcvs autoconfig buildpkg ccache distlocks sandbox sfperms" GENTOO_MIRRORS="http://distfiles.gentoo.org http://distro.ibiblio.org/pub/Linux/distributions/gentoo" MAKEOPTS="-j4" PKGDIR="/mnt/packages/node/nodebug" PORTAGE_TMPDIR="/scratch/gentoo-portage-tmp" PORTDIR="/usr/portage" SYNC="rsync://mirror.iat.sfu.ca/gentoo-portage" USE="x86 aalib acl alsa berkdb crypt cscope erandom f77 fam floppyboot fortran gcj gdbm hpn ipv6 java jikes jpeg kerberos krb5 ldap libwww mmx ncurses netboot objc pam pbs pcap perl pic png python quota quotas readline rpc sasl slang slp snmp spell sse ssh ssl tcpd urandom userlocales xfs xml xml2 zlib userland_GNU kernel_linux elibc_glibc" Unset: ASFLAGS, CTARGET, LANG, LC_ALL, LDFLAGS, LINGUAS, PORTDIR_OVERLAY
works fine for me # cd ~ # mv .bashrc{,.old} # echo echo bashrc > /etc/bash/bashrc # ssh root@localhost ls /dev/null root@localhost's password: bashrc .bashrc /dev/null #
err that wasnt everything i did ... i also did this before ssh-ing # mv /etc/bash/bashrc{,.old} # echo echo .bashrc > .bashrc
hmm, ok. still one flaw. I can't put . /etc/profile in /etc/bash/bashrc as then there is an infinite loop. so shouldn't the profile.env/PATH/umask stuff be in /etc/bash/bashrc instead of /etc/profile, to ensure that they are always set?
not a flaw, put '. /etc/profile' in your ~/.bashrc as for moving stuff from /etc/profile to bashrc, i dont think that makes much sense /etc/profile is used by more shells than just bash
using ~/.bashrc is not possible. I need to ensure that it takes place for ALL users, regardless of their ~/.bashrc. the other possibility is to move the profile.env/PATH/umask stuff to a new file, and source that from the profile and global bashrc. This keeps the profile working for non-bash shells.
so add it to /etc/skel/.bashrc ;) at any rate, propose a clean solution and we'll consider it ...
ok, reopening this to work on the problem. did the baselayout work move to SVN? I'll write up something and generate up to date diffs against the current tree.
Ok, a patch that implements profile.global is attached now. Output with some debug info that shows how it works (I put echo statements at each entry and exit point of the scripts, note that bashrc has two exit points). Run a shell script, this should NOT exec any of the stuff node001 ~ # bash test.sh node001 ~ # Test a login shell: node001 ~ # bash --login Start of /etc/profile Start of /etc/profile.global End of /etc/profile.global Start of /etc/bash/bashrc Interactive End of /etc/bash/bashrc End of /etc/profile node001 ~ # logout Don't load profile. node001 ~ # bash --noprofile Start of /etc/bash/bashrc Interactive End of /etc/bash/bashrc Don't load any startup scripts. node001 ~ # bash --norc bash-3.00# exit Posix compliant, startup scripts from different location. node001 ~ # bash --posix bash-3.00# exit Interactive SSH login node001 ~ # ssh node002 Last login: Thu Jul 21 23:06:06 2005 from node001 Start of /etc/profile Start of /etc/profile.global End of /etc/profile.global Start of /etc/bash/bashrc Interactive End of /etc/bash/bashrc End of /etc/profile node002 ~ # logout Connection to node002 closed. Non-interactive login node001 ~ # ssh node002 /bin/true Start of /etc/bash/bashrc Start of /etc/profile.global End of /etc/profile.global Non-Interactive End of /etc/bash/bashrc node001 ~ #
Created attachment 64029 [details, diff] Implement /etc/profile.global
The non-bash shells will need some entries like the change in bashrc to ensure they load /etc/profile.global when they are in their non-interactive case.
that's pretty confusing/ugly should be a better way to do this without creating another file
It looks like its doing the right thing without --noprofile and --norc, but that is to be expected, and if your users/whoever does that and expect things to work like usual, they should be beaten with a big club. As for --posix .. that really means emulate old sh, and anybody doing that and not expecting a bare shell without all the bells and wistles... nuff said. As for the other example about running something via ssh .. that is as expected as well ... if you really want all the bells and wistles with that, do something like: $ssh node002 bash -l -c /bin/true Or make a script. Or add to /etc/bash/bashrc: [[ ${-/i/} != "$-" ]] && { old_version=$BASH_VERSION unset BASH_VERSION source /etc/profile export BASH_VERSION=$old_version } So really, I do not see the issue, as running a command via ssh should not by default provide 'some environment for users'.
cheers