Environment variable in a stored procedure
Posted in 2011
Franck asked how to use shell variables like $HOME inside a stored procedure's SYSTEM() call, so hard-coded paths don't need editing after dbexport/dbimport to another server. Answers: environment variables aren't available in a database session; you can query sysmaster:sysenv/sysenvses (but HOME usually isn't there), or build the path from INFORMIXDIR plus USER, or pass the user to a generic wrapper script that resolves HOME in the shell. John Miller posted a C UDR using getenv() (with compile/register script) to read env vars; others noted it would return the engine process's HOME, and suggested getpwnam() to look up a given user's home directory. No single choice confirmed by the poster.
Auto-generated by DrWatson from the posts below — may be imperfect; read the full thread.
Topics: Stored Procedures & SPL, Migration, Import/Export & Data Conversion
Hi all,
I'd like to know how to use the environment variables in a stored
procedure, for example $HOME, when I call the SYSTEM command ?
By example :
CREATE PROCEDURE proc
SYSTEM('$HOME/myprog.sh');
END PROCEDURE;
Currently, we must write :
CREATE PROCEDURE proc
SYSTEM('/home/user/myprog.sh');
END PROCEDURE;
When we do a dbexport and a dbimport of the database in another server,
we must change the stored procedure to modify the directory.
Regards,
--
Franck Thomas
ConsultiX
franck.thomas@consult-ix.fr
Téléphone : 33 (0) 1 39 12 18 00
Mobile : 33 (0) 6 78 81 09 33
Fax : 33 (0) 1 39 12 18 18
Environment variables are properties of a user SHELL. They're not available
in the database session, since it's not a SHELL.
For your specific issue you could do something like:
1- Create a generic script in a specific location
(/usr/informix/run_script.sh)
2- Make that script receive two parameters (user, script)
3- Inside the script find the user's HOME and then run the script from there
Alternative you could run the generic script and find the $USER inside
Eventually you could have a C function that given a user would return it's
HOME and call it before you construct the SYSTEM command...
But I suppose your example is a simplification. The main point is that you
can't expect to have user SHELL environment variables in the database
session level.
You can have some of them inside the scripts called (because then, you'll be
in a SHELL).
Regards.
On Fri, Feb 18, 2011 at 12:00 PM, Franck THOMAS <franck.thomas@consult-ix.fr
> wrote:
> Hi all,
>
> I'd like to know how to use the environment variables in a stored
> procedure, for example $HOME, when I call the SYSTEM command ?
>
> By example :
>
> CREATE PROCEDURE proc>
> SYSTEM('$HOME/myprog.sh');
>
> END PROCEDURE;
>
> Currently, we must write :
> CREATE PROCEDURE proc>
> SYSTEM('/home/user/myprog.sh');
>
> END PROCEDURE;
>
> When we do a dbexport and a dbimport of the database in another server,
> we must change the stored procedure to modify the directory.
>
> Regards,
>
> --
> Franck Thomas
> ConsultiX
> franck.thomas@consult-ix.fr
> Téléphone : 33 (0) 1 39 12 18 00
> Mobile : 33 (0) 6 78 81 09 33
> Fax : 33 (0) 1 39 12 18 18
>
>
>
>
*******************************************************************************
> Forum Note: Use "Reply" to post a response in the discussion forum.
>
>
--
Fernando Nunes
Portugal
http://informix-technology.blogspot.com
My email works... but I don't check it frequently...
--0015174c3b3ac513eb049c8d8c43
You cannot just use environment variables within stored procedures like
that. You can get some of the environment variables that were in the server
environment, but not all, from the sysmaster:sysenv table, and you can get
some of the environment variables from your own session from the
sysmaster:sysenvses table:
select * from sysenvses where envses_sid = dbinfo('sessionid');
However, at least on my system, $HOME is not one of them. I would suggest
that since the server's $INFORMIXDIR is included in sysenv you place a
directory in INFORMIXDIR that will always be the same everywhere and will
always point to a directory containing symbolic links to each user's home or
bin directory named after the user's username. Call it appbin, then in your
procedure you can do:
select env_value into appbin from sysmaster:sysenv where env_name =
'INFORMIXDIR';
let command = rtrim( appbin ) || '/appbin/' || rtrim(USER) || '/myprog.sh'
system( command );
Art
Art S. Kagel
Advanced DataTools (www.advancedatatools.com)
IIUG Board of Directors (art@iiug.org)
Blog: http://informix-myview.blogspot.com/
Disclaimer: Please keep in mind that my own opinions are my own opinions and
do not reflect on my employer, Advanced DataTools, the IIUG, nor any other
organization with which I am associated either explicitly, implicitly, or by
inference. Neither do those opinions reflect those of other individuals
affiliated with any entity with which I am affiliated nor those of the
entities themselves.
On Fri, Feb 18, 2011 at 7:00 AM, Franck THOMAS
<franck.thomas@consult-ix.fr>wrote:
> Hi all,
>
> I'd like to know how to use the environment variables in a stored
> procedure, for example $HOME, when I call the SYSTEM command ?
>
> By example :
>
> CREATE PROCEDURE proc>
> SYSTEM('$HOME/myprog.sh');
>
> END PROCEDURE;
>
> Currently, we must write :
> CREATE PROCEDURE proc>
> SYSTEM('/home/user/myprog.sh');
>
> END PROCEDURE;
>
> When we do a dbexport and a dbimport of the database in another server,
> we must change the stored procedure to modify the directory.
>
> Regards,
>
> --
> Franck Thomas
> ConsultiX
> franck.thomas@consult-ix.fr
> Téléphone : 33 (0) 1 39 12 18 00
> Mobile : 33 (0) 6 78 81 09 33
> Fax : 33 (0) 1 39 12 18 18
>
>
>
>
*******************************************************************************
> Forum Note: Use "Reply" to post a response in the discussion forum.
>
>
--0015175ce1821ea91a049c8da25e
Thank you for the answers.
But, can we use a C function to get the $HOME variable in the Informix
database who will call as a stored procedure ?
Someone told me that is possible, but I don't know how to do ?
Regards
Le 18/02/2011 13:27, Art Kagel a écrit :
> You cannot just use environment variables within stored procedures like
> that. You can get some of the environment variables that were in the server
> environment, but not all, from the sysmaster:sysenv table, and you can get
> some of the environment variables from your own session from the
> sysmaster:sysenvses table:
>
> select * from sysenvses where envses_sid = dbinfo('sessionid');>
> However, at least on my system, $HOME is not one of them. I would suggest
> that since the server's $INFORMIXDIR is included in sysenv you place a
> directory in INFORMIXDIR that will always be the same everywhere and will
> always point to a directory containing symbolic links to each user's home or
> bin directory named after the user's username. Call it appbin, then in your
> procedure you can do:
>
> select env_value into appbin from sysmaster:sysenv where env_name =
> 'INFORMIXDIR';
> let command = rtrim( appbin ) || '/appbin/' || rtrim(USER) || '/myprog.sh'
> system( command );
>
> Art
>
> Art S. Kagel
> Advanced DataTools (www.advancedatatools.com)
> IIUG Board of Directors (art@iiug.org)
> Blog: http://informix-myview.blogspot.com/
>
> Disclaimer: Please keep in mind that my own opinions are my own opinions and
> do not reflect on my employer, Advanced DataTools, the IIUG, nor any other
> organization with which I am associated either explicitly, implicitly, or by
> inference. Neither do those opinions reflect those of other individuals
> affiliated with any entity with which I am affiliated nor those of the
> entities themselves.
>
> On Fri, Feb 18, 2011 at 7:00 AM, Franck THOMAS
> <franck.thomas@consult-ix.fr>wrote:
>
>> Hi all,
>>
>> I'd like to know how to use the environment variables in a stored
>> procedure, for example $HOME, when I call the SYSTEM command ?
>>
>> By example :
>>
>> CREATE PROCEDURE proc>>
>> SYSTEM('$HOME/myprog.sh');
>>
>> END PROCEDURE;
>>
>> Currently, we must write :
>> CREATE PROCEDURE proc>>
>> SYSTEM('/home/user/myprog.sh');
>>
>> END PROCEDURE;
>>
>> When we do a dbexport and a dbimport of the database in another server,
>> we must change the stored procedure to modify the directory.
>>
>> Regards,
>>
>> --
>> Franck Thomas
>> ConsultiX
>> franck.thomas@consult-ix.fr
>> Téléphone : 33 (0) 1 39 12 18 00
>> Mobile : 33 (0) 6 78 81 09 33
>> Fax : 33 (0) 1 39 12 18 18
>>
>>
>>
>>
>
*******************************************************************************
>> Forum Note: Use "Reply" to post a response in the discussion forum.
>>
>>
> --0015175ce1821ea91a049c8da25e
>
>
>
*******************************************************************************
> Forum Note: Use "Reply" to post a response in the discussion forum.
>
>
--
Franck Thomas
ConsultiX
franck.thomas@consult-ix.fr
Téléphone : 33 (0) 1 39 12 18 00
Mobile : 33 (0) 6 78 81 09 33
Fax : 33 (0) 1 39 12 18 18
Here is the code, and a script to compile the code and register the
function
in a database called "d1". Hope it helps.
#-------------------------------------c_udr.c--------------------------=
---------------------
#include "dmi/milib.h"
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <string.h>
mi_lvarchar *
jfm_getenv(mi_lvarchar *str, MI_FPARAM *fparam)
{
char *tmp;
char *value;
if ( mi_switch_mem_duration(PER_ROUTINE) =3D=3D MI_ERROR ||
( tmp =3D mi_lvarchar_to_string(str)) =3D=3D NULL )
return NULL;
if ( (value =3D getenv(tmp)) =3D=3D NULL)
{
/* Return SQL NULL if the env does not exist */
mi_fp_setreturnisnull(fparam, 0 , MI_TRUE);
return NULL;
}
return mi_string_to_lvarchar(value);
}
#---------------------COMPILE SCRIPT FOR LINUX
----------------------------------------------
#!/bin/sh -x
gcc -I$INFORMIXDIR/incl -fPIC -g -c -Wall c_udr.c
gcc -shared -Wl,-soname,c_udr_lib.so \\\\
-o c_udr_lib.so c_udr.o -lc
cp c_udr_lib.so $INFORMIXDIR/lib/c_udr_lib.so
ls -l $INFORMIXDIR/lib/c_udr_lib.so
dbaccess - -<<END
create database d1 with log;
create function mygetenv( input lvarchar(32) )
returning lvarchar(256)external name "$INFORMIXDIR/lib/c_udr_lib.so(jfm_getenv)" language c;
execute function mygetenv("HOME");
execute function mygetenv("INFORMIXDIR");
execute function mygetenv("NONE");
END
John F. Miller III
STSM, Embedability Architect
miller3@us.ibm.com
503-578-5645
IBM Informix Dynamic Server (IDS)
ids-bounces@iiug.org wrote on 02/18/2011 11:08:08 AM:
> [image removed]
>
> Re: Environment variable in a stored procedure [22833]
>
> Franck THOMAS
>
> to:
>
> ids
>
> 02/18/2011 11:09 AM
>
> Sent by:
>
> ids-bounces@iiug.org
>
> [image removed]
>
> From:
>
> "Franck THOMAS" <franck.thomas@consult-ix.fr>
>
> To:
>
> ids@iiug.org
>
> Sent by:
>
> ids-bounces@iiug.org
>
> Please respond to ids@iiug.org
>
> Thank you for the answers.
> But, can we use a C function to get the $HOME variable in the Informi=
x
> database who will call as a stored procedure ?
> Someone told me that is possible, but I don't know how to do ?
>
> Regards
>
> Le 18/02/2011 13:27, Art Kagel a =E9crit :
> > You cannot just use environment variables within stored procedures =
like
> > that. You can get some of the environment variables that were in th=
e
server
> > environment, but not all, from the sysmaster:sysenv table, and you =
can
get
> > some of the environment variables from your own session from the
> > sysmaster:sysenvses table:
> >
> > select * from sysenvses where envses_sid =3D dbinfo('sessionid');> >
> > However, at least on my system, $HOME is not one of them. I would
suggest
> > that since the server's $INFORMIXDIR is included in sysenv you plac=
e a
> > directory in INFORMIXDIR that will always be the same everywhere an=
d
will
> > always point to a directory containing symbolic links to each
> user's home or
> > bin directory named after the user's username. Call it appbin, then=
in
your
> > procedure you can do:
> >
> > select env_value into appbin from sysmaster:sysenv where env_name =3D=
> > 'INFORMIXDIR';
> > let command =3D rtrim( appbin ) || '/appbin/' || rtrim(USER) ||
'/myprog.sh'
> > system( command );
> >
> > Art
> >
> > Art S. Kagel
> > Advanced DataTools (www.advancedatatools.com)
> > IIUG Board of Directors (art@iiug.org)
> > Blog: http://informix-myview.blogspot.com/
> >
> > Disclaimer: Please keep in mind that my own opinions are my own
> opinions and
> > do not reflect on my employer, Advanced DataTools, the IIUG, nor an=
y
other
> > organization with which I am associated either explicitly,
> implicitly, or by
> > inference. Neither do those opinions reflect those of other individ=
uals
> > affiliated with any entity with which I am affiliated nor those of =
the
> > entities themselves.
> >
> > On Fri, Feb 18, 2011 at 7:00 AM, Franck THOMAS
> > <franck.thomas@consult-ix.fr>wrote:
> >
> >> Hi all,
> >>
> >> I'd like to know how to use the environment variables in a stored
> >> procedure, for example $HOME, when I call the SYSTEM command ?
> >>
> >> By example :
> >>
> >> CREATE PROCEDURE proc> >>
> >> SYSTEM('$HOME/myprog.sh');
> >>
> >> END PROCEDURE;
> >>
> >> Currently, we must write :
> >> CREATE PROCEDURE proc> >>
> >> SYSTEM('/home/user/myprog.sh');
> >>
> >> END PROCEDURE;
> >>
> >> When we do a dbexport and a dbimport of the database in another
server,
> >> we must change the stored procedure to modify the directory.
> >>
> >> Regards,
> >>
> >> --
> >> Franck Thomas
> >> ConsultiX
> >> franck.thomas@consult-ix.fr
> >> T=E9l=E9phone : 33 (0) 1 39 12 18 00
> >> Mobile : 33 (0) 6 78 81 09 33
> >> Fax : 33 (0) 1 39 12 18 18
> >>
> >>
> >>
> >>
> >
>
***********************************************************************=
********
> >> Forum Note: Use "Reply" to post a response in the discussion forum=
.
> >>
> >>
> > --0015175ce1821ea91a049c8da25e
> >
> >
> >
>
***********************************************************************=
********
> > Forum Note: Use "Reply" to post a response in the discussion forum.=
> >
> >
>
> --
> Franck Thomas
> ConsultiX
> franck.thomas@consult-ix.fr
> T=E9l=E9phone : 33 (0) 1 39 12 18 00
> Mobile : 33 (0) 6 78 81 09 33
> Fax : 33 (0) 1 39 12 18 18
>
>
>
***********************************************************************=
********
> Forum Note: Use "Reply" to post a response in the discussion forum.=
>=
One problem is *which* $HOME variable...
If you're running a stored procedure - thats running on the database
server (remember - this is Client/Server) - so even if you did get
$HOME - as I understand it - you'd only be getting the $HOME for the
process that started the informix engine..
On 18 February 2011 19:08, Franck THOMAS <franck.thomas@consult-ix.fr> wrote:
> Thank you for the answers.
> But, can we use a C function to get the $HOME variable in the Informix
> database who will call as a stored procedure ?
> Someone told me that is possible, but I don't know how to do ?
>
> Regards
>
> Le 18/02/2011 13:27, Art Kagel a écrit :
>> You cannot just use environment variables within stored procedures like
>> that. You can get some of the environment variables that were in the server
>> environment, but not all, from the sysmaster:sysenv table, and you can get
>> some of the environment variables from your own session from the
>> sysmaster:sysenvses table:
>>
>> select * from sysenvses where envses_sid = dbinfo('sessionid');>>
>> However, at least on my system, $HOME is not one of them. I would suggest
>> that since the server's $INFORMIXDIR is included in sysenv you place a
>> directory in INFORMIXDIR that will always be the same everywhere and will
>> always point to a directory containing symbolic links to each user's home or
>> bin directory named after the user's username. Call it appbin, then in your
>> procedure you can do:
>>
>> select env_value into appbin from sysmaster:sysenv where env_name =
>> 'INFORMIXDIR';
>> let command = rtrim( appbin ) || '/appbin/' || rtrim(USER) || '/myprog.sh'
>> system( command );
>>
>> Art
>>
>> Art S. Kagel
>> Advanced DataTools (www.advancedatatools.com)
>> IIUG Board of Directors (art@iiug.org)
>> Blog: http://informix-myview.blogspot.com/
>>
>> Disclaimer: Please keep in mind that my own opinions are my own opinions and
>> do not reflect on my employer, Advanced DataTools, the IIUG, nor any other
>> organization with which I am associated either explicitly, implicitly, or by
>> inference. Neither do those opinions reflect those of other individuals
>> affiliated with any entity with which I am affiliated nor those of the
>> entities themselves.
>>
>> On Fri, Feb 18, 2011 at 7:00 AM, Franck THOMAS
>> <franck.thomas@consult-ix.fr>wrote:
>>
>>> Hi all,
>>>
>>> I'd like to know how to use the environment variables in a stored
>>> procedure, for example $HOME, when I call the SYSTEM command ?
>>>
>>> By example :
>>>
>>> CREATE PROCEDURE proc>>>
>>> SYSTEM('$HOME/myprog.sh');
>>>
>>> END PROCEDURE;
>>>
>>> Currently, we must write :
>>> CREATE PROCEDURE proc>>>
>>> SYSTEM('/home/user/myprog.sh');
>>>
>>> END PROCEDURE;
>>>
>>> When we do a dbexport and a dbimport of the database in another server,
>>> we must change the stored procedure to modify the directory.
>>>
>>> Regards,
>>>
>>> --
>>> Franck Thomas
>>> ConsultiX
>>> franck.thomas@consult-ix.fr
>>> Téléphone : 33 (0) 1 39 12 18 00
>>> Mobile : 33 (0) 6 78 81 09 33
>>> Fax : 33 (0) 1 39 12 18 18
>>>
>>>
>>>
>>>
>>
>
*******************************************************************************
>>> Forum Note: Use "Reply" to post a response in the discussion forum.
>>>
>>>
>> --0015175ce1821ea91a049c8da25e
>>
>>
>>
>
*******************************************************************************
>> Forum Note: Use "Reply" to post a response in the discussion forum.
>>
>>
>
> --
> Franck Thomas
> ConsultiX
> franck.thomas@consult-ix.fr
> Téléphone : 33 (0) 1 39 12 18 00
> Mobile : 33 (0) 6 78 81 09 33
> Fax : 33 (0) 1 39 12 18 18
>
>
>
*******************************************************************************
> Forum Note: Use "Reply" to post a response in the discussion forum.
>
>
If its only $HOME you want, can't you use ~/myprog.sh?
On 2/18/2011 3:01 PM, Mike Aubury wrote:
> One problem is *which* $HOME variable...
> If you're running a stored procedure - thats running on the databas=
e
> server (remember - this is Client/Server) - so even if you did get
> $HOME - as I understand it - you'd only be getting the $HOME for th=
e
> process that started the informix engine..
>
> On 18 February 2011 19:08, Franck THOMAS<franck.thomas@consult-ix.f=
r> wrote:
>> Thank you for the answers.
>> But, can we use a C function to get the $HOME variable in the Info=
rmix
>> database who will call as a stored procedure ?
>> Someone told me that is possible, but I don't know how to do ?
>>
>> Regards
>>
>> Le 18/02/2011 13:27, Art Kagel a =E9crit :
>>> You cannot just use environment variables within stored procedure=
s like
>>> that. You can get some of the environment variables that were in =
the server
>>> environment, but not all, from the sysmaster:sysenv table, and yo=
u can get
>>> some of the environment variables from your own session from the
>>> sysmaster:sysenvses table:
>>>
>>> select * from sysenvses where envses_sid =3D dbinfo('sessionid');>>>
>>> However, at least on my system, $HOME is not one of them. I would=
suggest
>>> that since the server's $INFORMIXDIR is included in sysenv you pl=
ace a
>>> directory in INFORMIXDIR that will always be the same everywhere =
and will
>>> always point to a directory containing symbolic links to each use=
r's home
> or
>>> bin directory named after the user's username. Call it appbin, th=
en in your
>>> procedure you can do:
>>>
>>> select env_value into appbin from sysmaster:sysenv where env_name=
=3D
>>> 'INFORMIXDIR';
>>> let command =3D rtrim( appbin ) || '/appbin/' || rtrim(USER) || '=
/myprog.sh'
>>> system( command );
>>>
>>> Art
>>>
>>> Art S. Kagel
>>> Advanced DataTools (www.advancedatatools.com)
>>> IIUG Board of Directors (art@iiug.org)
>>> Blog: http://informix-myview.blogspot.com/
>>>
>>> Disclaimer: Please keep in mind that my own opinions are my own o=
pinions
> and
>>> do not reflect on my employer, Advanced DataTools, the IIUG, nor =
any other
>>> organization with which I am associated either explicitly, implic=
itly, or
> by
>>> inference. Neither do those opinions reflect those of other indiv=
iduals
>>> affiliated with any entity with which I am affiliated nor those o=
f the
>>> entities themselves.
>>>
>>> On Fri, Feb 18, 2011 at 7:00 AM, Franck THOMAS
>>> <franck.thomas@consult-ix.fr>wrote:
>>>
>>>> Hi all,
>>>>
>>>> I'd like to know how to use the environment variables in a store=
d
>>>> procedure, for example $HOME, when I call the SYSTEM command ?
>>>>
>>>> By example :
>>>>
>>>> CREATE PROCEDURE proc>>>>
>>>> SYSTEM('$HOME/myprog.sh');
>>>>
>>>> END PROCEDURE;
>>>>
>>>> Currently, we must write :
>>>> CREATE PROCEDURE proc>>>>
>>>> SYSTEM('/home/user/myprog.sh');
>>>>
>>>> END PROCEDURE;
>>>>
>>>> When we do a dbexport and a dbimport of the database in another =
server,
>>>> we must change the stored procedure to modify the directory.
>>>>
>>>> Regards,
>>>>
>>>> --=20
>>>> Franck Thomas
>>>> ConsultiX
>>>> franck.thomas@consult-ix.fr
>>>> T=E9l=E9phone : 33 (0) 1 39 12 18 00
>>>> Mobile : 33 (0) 6 78 81 09 33
>>>> Fax : 33 (0) 1 39 12 18 18
>>>>
>>>>
>>>>
>>>>
> *******************************************************************=
************
>>>> Forum Note: Use "Reply" to post a response in the discussion for=
um.
>>>>
>>>>
>>> --0015175ce1821ea91a049c8da25e
>>>
>>>
>>>
> *******************************************************************=
************
>>> Forum Note: Use "Reply" to post a response in the discussion foru=
m.
>>>
>>>
>> --=20
>> Franck Thomas
>> ConsultiX
>> franck.thomas@consult-ix.fr
>> T=E9l=E9phone : 33 (0) 1 39 12 18 00
>> Mobile : 33 (0) 6 78 81 09 33
>> Fax : 33 (0) 1 39 12 18 18
>>
>>
>>
> *******************************************************************=
************
>> Forum Note: Use "Reply" to post a response in the discussion forum=
.
>>
>>
>
> *******************************************************************=
************
> Forum Note: Use "Reply" to post a response in the discussion for=
um.
>
I'm afraid I didn't clarify this...
The problem is where you try to get the $HOME or "^" etc.
Only AFTER the SYSTEM call is being executed it makes sense.
Now... If the problem is finding the HOMEDIR of some user, than you can in
fact call a C function which must take the USER as argument and then calls
some OS function with it...
The function would probably be getpwnam(user) which returns a structure with
the fields of /etc/passwd in which you'll find HOMEDIR.
Regards.
On Fri, Feb 18, 2011 at 8:26 PM, David Zinder <zinder@ztechz.com> wrote:
> If its only $HOME you want, can't you use ~/myprog.sh?
>
> On 2/18/2011 3:01 PM, Mike Aubury wrote:
> > One problem is *which* $HOME variable...
> > If you're running a stored procedure - thats running on the databas=
> e
> > server (remember - this is Client/Server) - so even if you did get
> > $HOME - as I understand it - you'd only be getting the $HOME for th=
> e
> > process that started the informix engine..
> >
> > On 18 February 2011 19:08, Franck THOMAS<franck.thomas@consult-ix.f=
> r> wrote:
> >> Thank you for the answers.
> >> But, can we use a C function to get the $HOME variable in the Info=
> rmix
> >> database who will call as a stored procedure ?
> >> Someone told me that is possible, but I don't know how to do ?
> >>
> >> Regards
> >>
> >> Le 18/02/2011 13:27, Art Kagel a =E9crit :
> >>> You cannot just use environment variables within stored procedure=
> s like
> >>> that. You can get some of the environment variables that were in =
> the server
> >>> environment, but not all, from the sysmaster:sysenv table, and yo=
> u can get
> >>> some of the environment variables from your own session from the
> >>> sysmaster:sysenvses table:
> >>>
> >>> select * from sysenvses where envses_sid =3D dbinfo('sessionid');> >>>
> >>> However, at least on my system, $HOME is not one of them. I would=
> suggest
> >>> that since the server's $INFORMIXDIR is included in sysenv you pl=
> ace a
> >>> directory in INFORMIXDIR that will always be the same everywhere =
> and will
> >>> always point to a directory containing symbolic links to each use=
> r's home
> > or
> >>> bin directory named after the user's username. Call it appbin, th=
> en in your
> >>> procedure you can do:
> >>>
> >>> select env_value into appbin from sysmaster:sysenv where env_name=
> =3D
> >>> 'INFORMIXDIR';
> >>> let command =3D rtrim( appbin ) || '/appbin/' || rtrim(USER) || '=
> /myprog.sh'
> >>> system( command );
> >>>
> >>> Art
> >>>
> >>> Art S. Kagel
> >>> Advanced DataTools (www.advancedatatools.com)
> >>> IIUG Board of Directors (art@iiug.org)
> >>> Blog: http://informix-myview.blogspot.com/
> >>>
> >>> Disclaimer: Please keep in mind that my own opinions are my own o=
> pinions
> > and
> >>> do not reflect on my employer, Advanced DataTools, the IIUG, nor =
> any other
> >>> organization with which I am associated either explicitly, implic=
> itly, or
> > by
> >>> inference. Neither do those opinions reflect those of other indiv=
> iduals
> >>> affiliated with any entity with which I am affiliated nor those o=
> f the
> >>> entities themselves.
> >>>
> >>> On Fri, Feb 18, 2011 at 7:00 AM, Franck THOMAS
> >>> <franck.thomas@consult-ix.fr>wrote:
> >>>
> >>>> Hi all,
> >>>>
> >>>> I'd like to know how to use the environment variables in a store=
> d
> >>>> procedure, for example $HOME, when I call the SYSTEM command ?
> >>>>
> >>>> By example :
> >>>>
> >>>> CREATE PROCEDURE proc> >>>>
> >>>> SYSTEM('$HOME/myprog.sh');
> >>>>
> >>>> END PROCEDURE;
> >>>>
> >>>> Currently, we must write :
> >>>> CREATE PROCEDURE proc> >>>>
> >>>> SYSTEM('/home/user/myprog.sh');
> >>>>
> >>>> END PROCEDURE;
> >>>>
> >>>> When we do a dbexport and a dbimport of the database in another =
> server,
> >>>> we must change the stored procedure to modify the directory.
> >>>>
> >>>> Regards,
> >>>>
> >>>> --=20
> >>>> Franck Thomas
> >>>> ConsultiX
> >>>> franck.thomas@consult-ix.fr
> >>>> T=E9l=E9phone : 33 (0) 1 39 12 18 00
> >>>> Mobile : 33 (0) 6 78 81 09 33
> >>>> Fax : 33 (0) 1 39 12 18 18
> >>>>
> >>>>
> >>>>
> >>>>
> > *******************************************************************=
> ************
> >>>> Forum Note: Use "Reply" to post a response in the discussion for=
> um.
> >>>>
> >>>>
> >>> --0015175ce1821ea91a049c8da25e
> >>>
> >>>
> >>>
> > *******************************************************************=
> ************
> >>> Forum Note: Use "Reply" to post a response in the discussion foru=
> m.
> >>>
> >>>
> >> --=20
> >> Franck Thomas
> >> ConsultiX
> >> franck.thomas@consult-ix.fr
> >> T=E9l=E9phone : 33 (0) 1 39 12 18 00
> >> Mobile : 33 (0) 6 78 81 09 33
> >> Fax : 33 (0) 1 39 12 18 18
> >>
> >>
> >>
> > *******************************************************************=
> ************
> >> Forum Note: Use "Reply" to post a response in the discussion forum=
> ..
> >>
> >>
> >
> > *******************************************************************=
> ************
> > Forum Note: Use "Reply" to post a response in the discussion for=
> um.
> >
>
>
>
>
*******************************************************************************
> Forum Note: Use "Reply" to post a response in the discussion forum.
>
>
--
Fernando Nunes
Portugal
http://informix-technology.blogspot.com
My email works... but I don't check it frequently...
--0015174be8c4f355b3049c9804ae