delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2011/09/09/18:37:07

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=0.1 required=5.0 tests=AWL,BAYES_50,RCVD_NUMERIC_HELO,RP_MATCHES_RCVD,SPF_HELO_PASS
X-Spam-Check-By: sourceware.org
To: cygwin AT cygwin DOT com
From: Alan Sinclair <alan DOT sinclair AT citrix DOT com>
Subject: Re: setting environment for bash running via cygserver
Date: Fri, 9 Sep 2011 22:36:23 +0000 (UTC)
Lines: 38
Message-ID: <loom.20110910T003533-224@post.gmane.org>
References: <loom DOT 20110909T192501-772 AT post DOT gmane DOT org> <4E6A820A DOT 5020904 AT cygwin DOT com>
Mime-Version: 1.0
User-Agent: Loom/3.14 (http://gmane.org/)
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

Larry Hall (Cygwin <reply-to-list-only-lh <at> cygwin.com> writes:

> 
> On 9/9/2011 1:44 PM, Alan Sinclair wrote:
> > Where can I set environment variables which will be available in a
> > bash script running under cygserver?
> >
> > I need to ssh onto a remote cygserver and run bash scripts. RSA keys
> > are all set up so no password is needed and I can ssh onto the target
> > machine just fine by doing
> >      ssh me <at> machine bash ~/myscript.sh ARGS
> >
> > But myscript.sh is not getting the environment it needs. For example,
> > the script needs PROGRAMFILES, and also needs PROCESSOR_ARCHITEW6432
> > set in the environment on 64-bit OS.
> 
> Best to put them in a file you can source when you SSH into the other
> machine.  For the case above, you could then source that in your script
> or in some appropriate rc file if "SSH_CLIENT" is set in your environment.
> 


Thanks. Sourcing a file seems a usable approach. (I'm fairly new to cygwin
and unix in general). SSH_CLIENT is set (and SSH_CONNECTION too) but I
don't understand how to use that in reading an rc file.

When "myscript.sh" records the environment by doing "env > myfile", I can see 
that "USER=me" and "HOME=/home/me" both have expected values (though 
"USERNAME=cyg_server") so I can use HOME to locate the file to source. 

I had thought that /home/me/.bash_profile gets read when starting a 
non-login shell, so tried to export variables there, but I must be
misunderstanding something. The environment my script gets via ssh is different 
than I get when logged in via ssh, which is different again from when I'm logged 
in directly on the computer, and I'd like to understand why.





--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019