Re: why does bash not execute .bashrc with ssh -t ?

2008-10-15 Thread Jon Seymour
Chet,

Thanks for that info.

Due to the circumstances, recompiling bash isn't really an option for me, so
I decided to deal with it by having ssh invoke a script that could guarantee
~/.bashrc was sourced.

Regards,

jon seymour.

On Wed, Oct 15, 2008 at 1:24 PM, Chet Ramey [EMAIL PROTECTED] wrote:

 Jon Seymour wrote:

  Bash attempts to determine when it is being run by the remote shell
  daemon, usually rshd.  If bash determines it is being run by rshd, it
  reads  and  executes
  commands  from  ~/.bashrc,  if that file exists and is readable.  It
  will not do this if invoked as sh.  The --norc option may be used to
 inhibit
  this behavior, and
  the --rcfile option may be used to force another file to be read, but
  rshd does not generally invoke the shell with those options or allow them
 to
  be specified.
 
  However, when I use the ssh -t option, it would seem that allocation of a
  pseudo-tty is causing bash to assume that it is not being invoked by a
  remote shell daemon.

 Correct.  One of the criteria bash uses to decide whether it's being
 invoked by rshd or sshd is that its stdin is a socket.  Allocating a
 pseudo-tty makes that false.

 You can force bash to source .bashrc when it finds the various ssh
 variables in its startup environment by defining SSH_SOURCE_BASHRC
 in config-top.h and rebuilding bash.  That will cause .bashrc to be
 sourced more times than it should, but it will catch the cases you
 are interested in.

 Chet

 
  Is there any way I can have an ssh pseudo-tty and get bash to execute
  ~/.bashrc?
 
  jon seymour.


 --
 ``The lyf so short, the craft so long to lerne.'' - Chaucer

 Chet Ramey, ITS, CWRU[EMAIL PROTECTED]
 http://cnswww.cns.cwru.edu/~chet/ http://cnswww.cns.cwru.edu/%7Echet/



why does bash not execute .bashrc with ssh -t ?

2008-10-14 Thread Jon Seymour
I am trying to work out why .bashrc is not executing when I invoke ssh with
the -t option and _does_ execute when I invoke ssh without the -t option.

ssh -qt remote-host  which rsync  # indicates ~/.bashrc has not executed on
remote host
ssh -q remote-host   which rsync  # indicates ~/.bashrc has executed on
remote host

ssh -qt remote-host tty # reports /dev/pts/1
ssh -q remote-host tty # reports not a tty

ssh -qt remote-host echo '$-'  # reports hBc
ssh -q remote-host echo '$-'  # reports hBc

ssh -q remote-host ps -o pid,ppid,args -u xjsrs
  PID  PPID COMMAND
8704  8702 sshd: [EMAIL PROTECTED]
 8705  8704 ps -o pid,ppid,args -u xjsrs

ssh -qt remote-host ps -o pid,ppid,args -u xjsrs
  PID  PPID COMMAND
8733  8731 sshd: [EMAIL PROTECTED]/1
 8734  8733 ps -o pid,ppid,args -u xjsrs

According to echo '$-' neither shell is interactive.Yet, the one that is
started without a pseudo terminal does have .bashrc executed.

I added an debug statements to .bash_profile and it not getting executed in
either case.

There is no /etc/sshrc file and I don't have a ~/.ssh/rc file.

The bash version is:

GNU bash, version 3.00.15(1)-release (x86_64-redhat-linux-gnu)
Copyright (C) 2004 Free Software Foundation, Inc.

Upon reading the manual, the rule that bash seems to be using to decide that
.bashrc should be executed if -t is not specified, is this one:

Bash attempts to determine when it is being run by the remote shell
daemon, usually rshd.  If bash determines it is being run by rshd, it
reads  and  executes
commands  from  ~/.bashrc,  if that file exists and is readable.  It
will not do this if invoked as sh.  The --norc option may be used to inhibit
this behavior, and
the --rcfile option may be used to force another file to be read, but
rshd does not generally invoke the shell with those options or allow them to
be specified.

However, when I use the ssh -t option, it would seem that allocation of a
pseudo-tty is causing bash to assume that it is not being invoked by a
remote shell daemon.

Is there any way I can have an ssh pseudo-tty and get bash to execute
~/.bashrc?

jon seymour.


Re: why does bash not execute .bashrc with ssh -t ?

2008-10-14 Thread Chet Ramey
Jon Seymour wrote:

 Bash attempts to determine when it is being run by the remote shell
 daemon, usually rshd.  If bash determines it is being run by rshd, it
 reads  and  executes
 commands  from  ~/.bashrc,  if that file exists and is readable.  It
 will not do this if invoked as sh.  The --norc option may be used to inhibit
 this behavior, and
 the --rcfile option may be used to force another file to be read, but
 rshd does not generally invoke the shell with those options or allow them to
 be specified.
 
 However, when I use the ssh -t option, it would seem that allocation of a
 pseudo-tty is causing bash to assume that it is not being invoked by a
 remote shell daemon.

Correct.  One of the criteria bash uses to decide whether it's being
invoked by rshd or sshd is that its stdin is a socket.  Allocating a
pseudo-tty makes that false.

You can force bash to source .bashrc when it finds the various ssh
variables in its startup environment by defining SSH_SOURCE_BASHRC
in config-top.h and rebuilding bash.  That will cause .bashrc to be
sourced more times than it should, but it will catch the cases you
are interested in.

Chet

 
 Is there any way I can have an ssh pseudo-tty and get bash to execute
 ~/.bashrc?
 
 jon seymour.


-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer

Chet Ramey, ITS, CWRU[EMAIL PROTECTED]http://cnswww.cns.cwru.edu/~chet/