X-Recipient: archive-cygwin@delorie.com
X-SWARE-Spam-Status: No, hits=-3.2 required=5.0	tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,KHOP_RCVD_TRUST,KHOP_THREADED,RCVD_IN_DNSWL_LOW,RCVD_IN_HOSTKARMA_YE
X-Spam-Check-By: sourceware.org
MIME-Version: 1.0
In-Reply-To: <20121112124603.M62035@ds.net>
References: <CALvQJKtk12V1E1s68_4WvmAaswPk+=iaB=h3+Yupfz=TKAb9Fg@mail.gmail.com> <20121112124603.M62035@ds.net>
From: Ariel Sommeria <ariel.publique@gmail.com>
Date: Tue, 13 Nov 2012 21:23:38 +0100
Message-ID: <CALvQJKtSYgjY06RgOkWxnJV5hopHcYUbObScaxCn2EVVgMgDVg@mail.gmail.com>
Subject: Re: environment variables in ssh non-interactive shell
To: cygwin@cygwin.com
Content-Type: text/plain; charset=ISO-8859-1
X-IsSubscribed: yes
Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
Precedence: bulk
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie.com@cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com

So,
indeed there was no terminal attached. I like your example, but I
couldn't get it to run. It's as if bash doesn't work properly.
I got my script more or less to work, though it seems a bit inelegant like this:

ssh user@myserver -t -t < myscript.sh

It still runs a bit weird, but it does the trick for now.
thanks for pointing in the right direction!
Ariel

On Mon, Nov 12, 2012 at 2:06 PM, Brian Wilson <wilson@ds.net> wrote:
>> I'm trying to use environment variables to pilot a windows system
>> through cygwin+ssh. Things work nicely with an interactive shell, but
>> mess up with a non-interactive shell because my environment variables
>> aren't set.
> << -snip- >>
>> Does anyone have an idea what could be wrong?
>
> I'd suggest a simple approach like testing to see if there is a terminal
> attached then source in the .bashrc or other environment setting files.  Try
> something like this:
>
> [[ ! -t 1 ]] && [[ -f ~/.bashrc ]] && . ~/.bashrc
>
> If there is no terminal attached to the session, and there is a .bashrc file
> in ${HOME}, source the file into the current environment.  You may want to do
> something similar for the /etc/profile or ~/.profile files in which case I
> would use a regular "if" styled statement.  Make sure ${HOME} is set
> (obviously) or explicitly set the value if it is not set in the script.
> Carefully check the file permissions to make sure everything has the correct
> read, write, and execute permissions (i.e. You don't want to execute a file
> that just anyone can write into) or you may get a nasty surprise.
>
> if [[ ! -t 1 ]]
> then
>      echo -e "\n\tNo interactive terminal found for this session.\n\tSetting
> the environment.\n"
>      [[ "${HOME}" = "" ]] && HOME=/usr/<usr_dir>/...
>      if [[ -f /etc/profile ]]
>      then
>           . /etc/profile
>      fi
>      if [[ -f ${HOME}/.profile ]]
>      then
>           . ${HOME}/.profile
>      fi
>      if [[ -f ${HOME}/.bashrc ]]
>      then
>           . ${HOME}/.bashrc
>      fi
> fi
>
>
> --
> 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
>

--
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

