emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Brett Viren <bv@bnl.gov>
To: David Bjergaard <david.b@duke.edu>
Cc: emacs-orgmode Mailinglist <emacs-orgmode@gnu.org>
Subject: Re: Executing org shell blocks on remote machine over ssh
Date: Tue, 18 Nov 2014 14:03:19 -0500	[thread overview]
Message-ID: <ir4389gz5zc.fsf@lycastus.phy.bnl.gov> (raw)
In-Reply-To: <87ioic8j1u.fsf@duke.edu> (David Bjergaard's message of "Tue, 18 Nov 2014 13:23:09 -0500")

[-- Attachment #1: Type: text/plain, Size: 2034 bytes --]

David Bjergaard <david.b@duke.edu> writes:

> I know this is working "against the grain" of the literate programming
> paradigm where the document and the source code are coupled, and
> tangling the document produces a program that can be executed.  I'm just
> wondering if its possible.  If not that's fine.  Really I'm just trying
> to save myself a copy-paste (and the associated issues with it getting
> recorded in my .bash_history).

I usually come at it from the "reproducible research" angle which maybe
is more relaxed than literate programming.  In any case, I find it hard
to capture all the info needed to reproduce something and so I settle
for capturing as much as easily achievable - that is when I try at all
as capturing it in an RR org doc greatly increases the time I need to do
something.

Many of the software stacks I use also take significant time to
configure the end-user environment.  10 seconds is not unheard of and it
can be minutes if the stack lives on slow network disk.

I think the approach I suggested of caching the environment should work
for you.  Unfortunately, I do not know of a trivial, general way to do
this.  The "env" program comes close but does not spit out a format that
is immediately consumable by the shell.  In particular, spaces in
variable values confound it.  It also lacks the "export" keyword.  And,
in any case is only close to sh syntax.  Any exported functions also
have to be handled properly

In your shoes, I'd probably write a small Python script that dumps the
"os.environ" dictionary holding the environment of the caller into a
form suitable for consumption by your shell.  You can call this dumper
in a shell code block at the top of your org file and source the result
as the first line in each subsequent shell code block.

A starting point would be something like the following, but this does
not properly handle and sh functions defined.

#!/usr/bin/env python
import os
for k,v in os.environ.items():
    print 'export %s="%s"' % (k,v)



Good luck!
-Brett.



[-- Attachment #2: Type: application/pgp-signature, Size: 180 bytes --]

  parent reply	other threads:[~2014-11-18 19:03 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-17 16:04 Executing org shell blocks on remote machine over ssh David Bjergaard
2014-11-17 22:50 ` Myles English
2014-11-18 15:55   ` Andreas Leha
2014-11-18 15:43 ` Brett Viren
2014-11-18 18:12   ` Ista Zahn
2014-11-18 18:23     ` David Bjergaard
2014-11-18 18:31       ` Ista Zahn
2014-11-18 19:03       ` Brett Viren [this message]
2014-11-18 19:52       ` Subhan Michael Tindall
2014-11-18 20:58     ` Brady Trainor
2014-11-18 22:01       ` Andreas Leha

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ir4389gz5zc.fsf@lycastus.phy.bnl.gov \
    --to=bv@bnl.gov \
    --cc=david.b@duke.edu \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).