Org Babel
Print Error of Code Block
Relevant SO questions:
Shell
ls --foo
#+RESULTS:
ls: unrecognized option '--foo' Try 'ls --help' for more information.
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
#+RESULTS:
Hi chrisc-ironnet! You've successfully authenticated, but GitHub does not provide shell access.
Python
python -c 'bar=b"ОФИС"''
Emacs Lisp
To print data structure, use :results value pp
'(("DeploymentName" "webserver") ("KeyName" "cfc"))
Params
#+RESULTS:
(("DeploymentName" "webserver") ("KeyName" "cfc"))
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:
#+begin_src bash :dir (host (getenv "HOST") (getenv "USER") "/home/ec2-user") pwd #+end_src