Reputation: 85
I'm using an org-mode file to do some filesystem monitoring. To that purpose I have a table in which I'm calling code blocks through org-sbe in the formulas. It looks like this:
#+NAME: part-size
#+BEGIN_SRC bash :var mach="" :var part="" :var bs="TB" :exports none :results silent
tmp=($(df -B ${bs} /net/${mach}/${part} | tail -1 ))
bc -l <<< "scale=2; ${tmp[1]}/1024/1024"
#+END_SRC
#+NAME: part-used
#+BEGIN_SRC bash :var mach="" :var part="" :var bs="TB" :exports none :results silent
tmp=($(df -B${bs} /net/${mach}/${part} | tail -1))
bc -l <<< "scale=2; ${tmp[2]}/1024/1024"
#+END_SRC
| machine | partition | size[TB] | used[TB] | available[TB] |
|---------+-----------+----------+----------+---------------|
| mach1 | part1 | 60.0 | 56.0 | 4.0 |
| mach1 | part2 | 15.0 | 12.5 | 2.5 |
| mach2 | part1 | 40.5 | 10.5 | 30.0 |
|---------+-----------+----------+----------+---------------|
| total | | 115.5 | 79.0 | 36.5 |
#+TBLFM: @>$3..@>$5=vsum(@I..II)::@2$3..@9$3='(org-sbe part-size (mach $$1) (part $$2) (bs \"1MB\"))::@2$4..@9$4='(org-sbe part-used (mach $$1) (part $$2) (bs \"1MB\"))::@2$5..@9$5=$-2 - $-1
My problem is that I export that file regularly and automatically to a web page but the content of the table doesn't get updated. So I'd like to know if there is a way to automatically re-apply the table formulas on export in the same way that you can run code blocks on export.
Upvotes: 4
Views: 317
Reputation: 6422
Here's a simplified example that gets an updated time in the table every time you export, using the mechanism that Seth Rothschild suggested in the comment:
* code :noexport:
#+begin_src emacs-lisp
(defun tables-recalc (backend)
(org-table-recalculate-buffer-tables))
(add-hook 'org-export-before-processing-hook #'tables-recalc)
#+end_src
#+RESULTS:
| tables-recalc |
* table
#+NAME: gettime
#+begin_src shell
date
#+end_src
| time |
|------------------------------|
| Wed Apr 11 16:27:09 EDT 2018 |
#+TBLFM: $> = '(org-sbe gettime)
Upvotes: 3