I use this in emacs to connect and execute commands remotely:

#+BEGIN_SRC sh :dir /ssh:app_user@

: /tmp

Recently, people have gone "cloud scaling" so the IP address changes often.

The IP address can be determined by this bash:

sentinel list staging | grep InService | ruby -ne '$_=~/\A  (.*?) /; puts $1' | tail -n 1

How can I modify the header

+BEGIN_SRC sh :dir /ssh:app_user@

to dynamically determine the IP address.


Assuming that your bash script only puts out the ip, you could use the following function:

(defun get-ssh-ip ()
  "Query the ip address and return the result as value for sh block header option :dir."
  (let ((ip (shell-command-to-string "sentinel list staging | grep InService | ruby -ne '$_=~/\A  (.*?) /; puts $1' | tail -n 1")))
    (format "/ssh:app_user@%s:/tmp" ip)))

And use it in your org files:

#+header: :exports both
#+header: :results output
#+BEGIN_SRC sh :dir (get-ssh-ip)

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.