From mboxrd@z Thu Jan 1 00:00:00 1970 From: Xi Shen Subject: Is it possible to pass variable to variables of src block? Date: Tue, 05 Dec 2017 05:19:28 +0000 Message-ID: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="94eb2c0d9a4a400ee7055f90fbb4" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:54340) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eM5dt-0006es-SF for Emacs-orgmode@gnu.org; Tue, 05 Dec 2017 00:19:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eM5ds-0002Qx-TX for Emacs-orgmode@gnu.org; Tue, 05 Dec 2017 00:19:41 -0500 Received: from mail-lf0-x235.google.com ([2a00:1450:4010:c07::235]:37824) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eM5ds-0002QN-J5 for Emacs-orgmode@gnu.org; Tue, 05 Dec 2017 00:19:40 -0500 Received: by mail-lf0-x235.google.com with SMTP id a12so21806872lfe.4 for ; Mon, 04 Dec 2017 21:19:40 -0800 (PST) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: "emacs-orgmode@gnu.org" --94eb2c0d9a4a400ee7055f90fbb4 Content-Type: text/plain; charset="UTF-8" Hi, http://orgmode.org/manual/var.html This wiki explains how to use variable inside a src block. But I wonder if it is possible to specify variable to the variables in the src definition. E.g. for the sql src block, I want to execute a script on different server. I want to define a variable for the ":dbhost" variable. Regards, David --94eb2c0d9a4a400ee7055f90fbb4 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi,


=
This wiki explains how to use variable inside a src block. But I wonde= r if it is possible to specify variable to the variables in the src definit= ion.

E.g. for the sql src block, I want to execute= a script on different server. I want to define a variable for the ":d= bhost" variable.


Regards,
David

--94eb2c0d9a4a400ee7055f90fbb4-- From mboxrd@z Thu Jan 1 00:00:00 1970 From: Michael Welle Subject: Re: Is it possible to pass variable to variables of src block? Date: Wed, 06 Dec 2017 10:31:06 +0100 Message-ID: <877eu0gq3p.fsf@luisa.c0t0d0s0.de> References: Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:42120) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eMW2t-0007Hp-GG for emacs-orgmode@gnu.org; Wed, 06 Dec 2017 04:31:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eMW2p-00014j-H2 for emacs-orgmode@gnu.org; Wed, 06 Dec 2017 04:31:15 -0500 Received: from mout.gmx.net ([212.227.17.20]:59535) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eMW2p-000137-7H for emacs-orgmode@gnu.org; Wed, 06 Dec 2017 04:31:11 -0500 Received: from stella.c0t0d0s0.de ([194.95.66.1]) by mail.gmx.com (mrgmx103 [212.227.17.168]) with ESMTPSA (Nemesis) id 0M09Ee-1fEL321nw4-00uFTx for ; Wed, 06 Dec 2017 10:31:08 +0100 Received: from Stella (stella.c0t0d0s0.de [192.168.42.1]) by stella.c0t0d0s0.de (Postfix) with ESMTP id 55FD7C419C for ; Wed, 6 Dec 2017 10:31:06 +0100 (CET) In-Reply-To: (Xi Shen's message of "Tue, 05 Dec 2017 05:19:28 +0000") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: emacs-orgmode@gnu.org Hello, Xi Shen writes: > Hi, > > http://orgmode.org/manual/var.html > > This wiki explains how to use variable inside a src block. But I wonder if > it is possible to specify variable to the variables in the src definition. > > E.g. for the sql src block, I want to execute a script on different server. > I want to define a variable for the ":dbhost" variable. did you think about something like this? (setq hmw/dbhost "db1") #+BEGIN_SRC sql :dbhost (symbol-value 'hmw/dbhost) :dbuser weather :database environment :engine postgresql select time, temperature from weather limit 20; #+END_SRC Regards hmw From mboxrd@z Thu Jan 1 00:00:00 1970 From: Xi Shen Subject: Re: Is it possible to pass variable to variables of src block? Date: Tue, 12 Dec 2017 06:30:01 +0000 Message-ID: References: <877eu0gq3p.fsf@luisa.c0t0d0s0.de> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="94eb2c0c89987af32805601ec87d" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:59253) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eOe51-00069C-At for emacs-orgmode@gnu.org; Tue, 12 Dec 2017 01:30:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eOe50-000135-7p for emacs-orgmode@gnu.org; Tue, 12 Dec 2017 01:30:15 -0500 Received: from mail-lf0-x234.google.com ([2a00:1450:4010:c07::234]:33177) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eOe4z-000110-VH for emacs-orgmode@gnu.org; Tue, 12 Dec 2017 01:30:14 -0500 Received: by mail-lf0-x234.google.com with SMTP id 74so21935904lfs.0 for ; Mon, 11 Dec 2017 22:30:13 -0800 (PST) In-Reply-To: <877eu0gq3p.fsf@luisa.c0t0d0s0.de> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: Michael Welle Cc: emacs-orgmode@gnu.org --94eb2c0c89987af32805601ec87d Content-Type: text/plain; charset="UTF-8" Hi Michael, Yes, I think this is a way to my previous question. But what I really want to achieve is to loop through a list of server names and execute a script on them. Say I have 20 different database server. How can I do a loop with each server? Regards, David On Wed, Dec 6, 2017 at 5:34 PM Michael Welle wrote: > Hello, > > Xi Shen writes: > > > Hi, > > > > http://orgmode.org/manual/var.html > > > > This wiki explains how to use variable inside a src block. But I wonder > if > > it is possible to specify variable to the variables in the src > definition. > > > > E.g. for the sql src block, I want to execute a script on different > server. > > I want to define a variable for the ":dbhost" variable. > did you think about something like this? > > > (setq hmw/dbhost "db1") > > #+BEGIN_SRC sql :dbhost (symbol-value 'hmw/dbhost) :dbuser weather > :database environment :engine postgresql > select time, temperature from weather limit 20; > #+END_SRC > > Regards > hmw > > --94eb2c0c89987af32805601ec87d Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Michael,

Yes, I think this is a way = to my previous question. But what I really want to achieve is to loop throu= gh a list of server names and execute a script on them.

Say I have 20 different database server. How can I do a loop with eac= h server?


Regards,
David<= /div>


O= n Wed, Dec 6, 2017 at 5:34 PM Michael Welle <mwe012008@gmx.net> wrote:
Hello,

Xi Shen <davi= dshen84@gmail.com> writes:

> Hi,
>
> http://orgmode.org/manual/var.html
>
> This wiki explains how to use variable inside a src block. But I wonde= r if
> it is possible to specify variable to the variables in the src definit= ion.
>
> E.g. for the sql src block, I want to execute a script on different se= rver.
> I want to define a variable for the ":dbhost" variable.
did you think about something like this?


(setq hmw/dbhost "db1")

#+BEGIN_SRC sql :dbhost (symbol-value 'hmw/dbhost) :dbuser weather :dat= abase environment :engine postgresql
select time, temperature from weather limit 20;
#+END_SRC

Regards
hmw

--94eb2c0c89987af32805601ec87d-- From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ihor Radchenko Subject: Re: Is it possible to pass variable to variables of src block? Date: Tue, 12 Dec 2017 15:17:11 +0800 Message-ID: <87fu8gwh3c.fsf@yantar92-laptop.i-did-not-set--mail-host-address--so-tickle-me> References: <877eu0gq3p.fsf@luisa.c0t0d0s0.de> Mime-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:41079) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eOepN-0000Fx-Sv for emacs-orgmode@gnu.org; Tue, 12 Dec 2017 02:18:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eOepI-0002DY-Ii for emacs-orgmode@gnu.org; Tue, 12 Dec 2017 02:18:09 -0500 Received: from mail-it0-x233.google.com ([2607:f8b0:4001:c0b::233]:44292) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eOepI-0002DL-Cg for emacs-orgmode@gnu.org; Tue, 12 Dec 2017 02:18:04 -0500 Received: by mail-it0-x233.google.com with SMTP id b5so22160172itc.3 for ; Mon, 11 Dec 2017 23:18:04 -0800 (PST) In-Reply-To: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: Xi Shen , Michael Welle Cc: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Hi David, One thing you can do is to make a code block, which will generate another code block, running your script with different arguments. Let me illustrate with a simple example: #+name: printecho #+BEGIN_SRC sh :var a=3D1 echo $a; #+END_SRC #+name: genscript #+BEGIN_SRC sh :var cmd=3D"printecho" :results raw output :wrap "src sh :n= oweb yes :results output" echo "cat << EOF" for x in "1" "2" "3" "4" "5" "6" "something"; do echo "<<$cmd(a=3D\"$x\")= >>"; done #+END_SRC #+RESULTS: genscript #+BEGIN_src sh :noweb yes :results output cat << EOF <> <> <> <> <> <> <> #+END_src #+RESULTS: : 1 : 2 : 3 : 4 : 5 : 6 : something Hope it helps. P.S. Does anyone know why the following does not evaluate noweb recursively? #+BEGIN_SRC sh :noweb yes :results output=20 <> #+END_SRC Regards, Ihor Xi Shen writes: > Hi Michael, > > Yes, I think this is a way to my previous question. But what I really want > to achieve is to loop through a list of server names and execute a script > on them. > > Say I have 20 different database server. How can I do a loop with each > server? > > > Regards, > David > > > On Wed, Dec 6, 2017 at 5:34 PM Michael Welle wrote: > >> Hello, >> >> Xi Shen writes: >> >> > Hi, >> > >> > http://orgmode.org/manual/var.html >> > >> > This wiki explains how to use variable inside a src block. But I wonder >> if >> > it is possible to specify variable to the variables in the src >> definition. >> > >> > E.g. for the sql src block, I want to execute a script on different >> server. >> > I want to define a variable for the ":dbhost" variable. >> did you think about something like this? >> >> >> (setq hmw/dbhost "db1") >> >> #+BEGIN_SRC sql :dbhost (symbol-value 'hmw/dbhost) :dbuser weather >> :database environment :engine postgresql >> select time, temperature from weather limit 20; >> #+END_SRC >> >> Regards >> hmw >> >> =2D-=20 Ihor Radchenko, PhD Student Singapore University of Technology and Design, 8 Somapah Road Singapore 487372 Email: yantar92@gmail.com, ihor_radchenko@mymail.sutd.edu.sg Tel: +6584017977 --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEERZAHPFbUe3JemmzmZHB2Kn2hHYsFAlovgngACgkQZHB2Kn2h HYvqUAf/XCGscnzIpI2+U7KZz6Al2WAYghgt3QAYYYtzF97ZP5GTGxeHMds3cAJ5 5IiV5PHDqnuCgZFc/XZ4IH4WmgJRdGVx/z8IwASaiuHLyocoCT6FCy9K1q0+P7Ne 08Gg2DPkH8TD5DME5sEHs+Gmltt4a6XfxEsICScl8o18wTqoF5mrobN82gPghtNO Hizjzl89ZzRCFCbU8mlvPMrVOc/U8goyhbvQe6BLWMKxUw9KuFzqtdADwmDXncyp kYu/ZiMd667lt8YnOkmuymbl4sjULqHRVLddasGw56xjiUFGxwMOQCAHA8+Rx63+ qxv6DkXVTNsscXqigEEK4K/1K6Cpfw== =4Ysn -----END PGP SIGNATURE----- --=-=-=-- From mboxrd@z Thu Jan 1 00:00:00 1970 From: Michael Welle Subject: Re: Is it possible to pass variable to variables of src block? Date: Wed, 13 Dec 2017 10:57:28 +0100 Message-ID: <87fu8fosqf.fsf@luisa.c0t0d0s0.de> References: <877eu0gq3p.fsf@luisa.c0t0d0s0.de> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:56090) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eP3nE-0001fy-FW for emacs-orgmode@gnu.org; Wed, 13 Dec 2017 04:57:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eP3nB-0004cU-Dk for emacs-orgmode@gnu.org; Wed, 13 Dec 2017 04:57:36 -0500 Received: from mout.gmx.net ([212.227.17.22]:51326) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eP3nB-0004bT-3P for emacs-orgmode@gnu.org; Wed, 13 Dec 2017 04:57:33 -0500 Received: from stella.c0t0d0s0.de ([194.95.66.1]) by mail.gmx.com (mrgmx101 [212.227.17.168]) with ESMTPSA (Nemesis) id 0Lat5o-1erTf8317A-00kNrR for ; Wed, 13 Dec 2017 10:57:30 +0100 Received: from Stella (stella.c0t0d0s0.de [192.168.42.1]) by stella.c0t0d0s0.de (Postfix) with ESMTP id 47559C409C for ; Wed, 13 Dec 2017 10:57:28 +0100 (CET) In-Reply-To: (Xi Shen's message of "Tue, 12 Dec 2017 06:30:01 +0000") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: emacs-orgmode@gnu.org Hello, Xi Shen writes: > Hi Michael, > > Yes, I think this is a way to my previous question. But what I really want > to achieve is to loop through a list of server names and execute a script > on them. > > Say I have 20 different database server. How can I do a loop with each > server? interestingly I did not found a good solution after a bit of thinking... The best I could come up with is something like this (which doesn't work): #+name: foosql #+BEGIN_SRC sql :dbuser weather :database environment :engine postgresql select time, temperature from weather limit 10; #+END_SRC #+begin_src emacs-lisp :results raw :var hosts=(list "db1" "db2" "db3") (dolist (host hosts) (org-sbe foosql (concat ":dbhost " host))) #+end_src Error: Symbol's definition is void: host. I guess that's caused by the way the macro is evaluated. And the result, if any, of the sql query had to be transformed back into a nice table for some use cases. Using other means of calling a code block, like #+call etc., aren't suitable for usage in a loop. So maybe someone can come up with a nice solution ;). Regards hmw