1

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

#+BEGIN_SRC sh :dir /ssh:app_user@34.143.149.84:/tmp
pwd
#+END_SRC

#+RESULTS:
: /tmp

Recently, people have gone "cloud scaling" so the IP address 34.143.149.84 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@34.143.149.84:/tmp

to dynamically determine the IP address.

1

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)
pwd
#+END_SRC

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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