Org Babel

Print Error of Code Block

Shell

ls --foo

NOT WORKING

Doesn't work:

echo "hi"
exit 1
set -u
echo $foo
echo "hi"
ssh -T github-work

Instead, this works though:

ssh -T github-work 2>&1 || true

Python

python -c 'bar=b"ОФИС"''

Emacs Lisp

To print data structure, use :results value pp

'(("DeploymentName" "webserver")
  ("KeyName" "cfc"))
Params

TRAMP

Single Hop

:dir /ssh:ec2-user@1.2.3.4:/

Double-Hop (Use a Bastion)

:dir /ssh:ec2-user@1.2.3.4|ssh:ec2-user@10.192.1.2:/

Copy File to Remote Machine

This leverages my host function.

(copy-file MyFile (host "ec2-user" "/tmp/my_file.txt" 'sudo) t)

IP Address Variable

Because you don't want to hard-code IP addresses in your source blocks like some kind of animal!

(defun host (user ip path &optional sudo)
  "Return a TRAMP string for SSHing to a remote host.
USER is a user name on the remote host IP. PATH is the path on
the remote host at which to execute the source block. If SUDO is
non-nil, use sudo on the remote host."
  (if sudo
      (s-lex-format "/ssh:${user}@${ip}|sudo:${ip}:${path}")
    (s-lex-format "/ssh:${user}@${ip}:${path}")))

Then set variables at the top of a file, and use something like:

#+header: :dir (host (getenv "HOST") (getenv "USER") "/home/ec2-user")
#+begin_src bash
 pwd
#+end_src