RE: set environment variable
Posted in 2008
The poster wanted an Informix 4GL program to set environment variables (e.g. INFORMIXSERVER, printer, user-level settings held in database tables) that would persist in the calling bash shell, since I4GL has no FGL_SETENV. Respondents explained this is impossible on Unix: a child process cannot alter its parent's environment; putenv/setenv only affect programs the 4GL itself RUNs. The accepted workaround is to have the 4GL write the variable assignments to a temporary file and have the shell 'source' it (or build a command string that sets the env and launches the app). The poster confirmed he solved it that way. Jonathan Leffler cautioned against relying on environment variables for security.
Auto-generated by DrWatson from the posts below — may be imperfect; read the full thread.
Topics: Stored Procedures & SPL, Connectivity: ESQL/C, 4GL & Embedded SQL
Perhaps I'm missing something.
Instead of the user running the 4GL program directly, have the user run a shell script that sets the variables and then calls the 4GL program.
> From: eferreyra@gmail.com
> Subject: Re: set environment variable
> Date: Fri, 21 Nov 2008 06:43:06 -0800
> To: informix-list@iiug.org
>
> Hi, thanks i do that, anyway the wole process is for set envirnment
> variables before an user runs his 4gl menu of programs.
>
> In other program that doenst have ui, i just DISPLAY several
> MYVAR=123; export MYVAR
> then i call it from a shell:
>
> fglgo my4gl >> /tmp/mktempfile
> source /tmp/mktempfile
> rm /tmp/mktempfile
>
> But now i need to show a options menu so DISPLAY to console cant help
> me :)
>
> thanks again!
>
>
> On 21 nov, 12:16, Mike Aubury <i...@aubit.com> wrote:
> > You can't really do that..
> >
> > You're testing for having set something in the environment from a process
> > thats been run and finished, and you cant set the environment in a parent
> > process from a child process.
> >
> > You can't even do that from a shell script - the closest you can get is
> > to 'source' the settings so they are read into the current settings. If you
> > want to take this approach - you might be able to generate a 'settings' file
> > and then source that, eg :
> >
> > $ fglgo my4gl> > # my4gl generates my4gl.env
> >
> > $ . my4gl.env
> > $ echo $MYVAR> >
> > You should be able to set the environment variables for use within the 4gl
> > program by calling the C function putenv or setenv (depending on your
> > platform) - but that will only set it for programs run from the 4gl program
> > (eg via a RUN command).
> > Of course - Aubit4GL has a "aclfgl_setenv" to make this easier ;-)
> >
> > HTH
> >
> > On Friday 21 November 2008 14:01:34 eferreyra wrote:
> >
> >
> >
> > > Hi, i note there is not a FGL_SETENV function in traditional Informix
> > > 4GL
> >
> > > Anybody has resolved how to set an environment variable (linux, bash)
> > > from 4gl program??
> >
> > > i need:
> >
> > > $ fglgo my4gl> >
> > > -- my4gl must set MYVAR=SOMEVALUE
> >
> > > $ echo $MYVAR> > > SOMEVALUE
> >
> > > Can make this works....
> >
> > > Thanks!
> > > _______________________________________________
> > > Informix-list mailing list
> > > Informix-l...@iiug.org
> > >http://www.iiug.org/mailman/listinfo/informix-list
> >
> > --
> > Mike Aubury
> >
> > http://www.aubit.com/
> > Aubit Computing Ltd is registered in England and Wales, Number: 3112827
> > Registered Address : Clayton House,59 Piccadilly,Manchester,M1 2AQ
>
> _______________________________________________
> Informix-list mailing list
> Informix-list@iiug.org
> http://www.iiug.org/mailman/listinfo/informix-list
_________________________________________________________________
Proud to be a PC? Show the world. Download the “I’m a PC” Messenger themepack now.
hthttp://clk.atdmt.com/MRT/go/119642558/direct/01/
the thing is we are a corporation where there is several enterprises, and (at least) each one have one informix online instance, anyway there are several informix instances... With this scenario we have users that access several instances, but this based on a permission scenario, not everybody access any informix instance of course. So we need to put some own logic in the .profile of the users sessions to app servers (i4gl app servers), we design a model where there are properties of the terminals (printer name, POS number, etc.) and properties of the user (user-level, default enteprise, etc.) and finally we have properties of the instance (informixserver, etc.) plus could be some combinations user+instance could have different user- level environment variable). So we design a script that is called on the .profile of the user session, it gets username, netbios name of the terminal, and the instance the user could have several instances enabled so there is the 4GL program that picks up a instance. with those three elements we build the environment variables for the session as a script, save this to a file, then do a source (.) with the file. finally we get from environment variables the directory to go and the program to execute for the user. Notice that the model is in informix tables and accessed by informix 4gl programs, prior the really get and build the user i4gl environment. Of course this is that way because we have a LOT of informix 4gl programs that builds our ERP and more subsystems, the programs uses a lot envirnment variables and cant do a cut-point redesign of the systems, we are in a slow migration where i4gl coexists with .net services. Hope you understand :) we are a complex mesh of technology and people...
eferreyra wrote: > the thing is we are a corporation where there is several enterprises, > and (at least) each one have one informix online instance, anyway > there are several informix instances... > > With this scenario we have users that access several instances, but > this based on a permission scenario, not everybody access any informix > instance of course. > > So we need to put some own logic in the .profile of the users sessions > to app servers (i4gl app servers), we design a model where there are > properties of the terminals (printer name, POS number, etc.) and > properties of the user (user-level, default enteprise, etc.) and > finally we have properties of the instance (informixserver, etc.) plus > could be some combinations user+instance could have different user- > level environment variable). > > So we design a script that is called on the .profile of the user > session, it gets username, netbios name of the terminal, and the > instance the user could have several instances enabled so there is the > 4GL program that picks up a instance. with those three elements we > build the environment variables for the session as a script, save this > to a file, then do a source (.) with the file. finally we get from > environment variables the directory to go and the program to execute > for the user. > > Notice that the model is in informix tables and accessed by informix > 4gl programs, prior the really get and build the user i4gl > environment. > > Of course this is that way because we have a LOT of informix 4gl > programs that builds our ERP and more subsystems, the programs uses a > lot envirnment variables and cant do a cut-point redesign of the > systems, we are in a slow migration where i4gl coexists with .net > services. > > Hope you understand :) we are a complex mesh of technology and > people... As others have said you can't set an environment variable and have it passed back to the calling program. The Unix environment variable just doesn't work like that. It's one-way. What you could do is build a command string in the 4GL program which includes both setting the environment and executing the program for the user. You would then run this command string from within the 4GL. This would, of course, leave your existing 4GL program waiting for the user program to execute. -- Ian Hotmail is for spammers. Real mail address is igoddard at nildram co uk
I was clarifing the scenario, i already resolved it building a file in the 4gl and then source (.) it from bash as suggested. Thanks On 24 nov, 11:33, Ian Goddard <godda...@hotmail.co.uk> wrote: > eferreyra wrote: > > the thing is we are a corporation where there is several enterprises, > > and (at least) each one have one informix online instance, anyway > > there are several informix instances... > > > With this scenario we have users that access several instances, but > > this based on a permission scenario, not everybody access any informix > > instance of course. > > > So we need to put some own logic in the .profile of the users sessions > > to app servers (i4gl app servers), we design a model where there are > > properties of the terminals (printer name, POS number, etc.) and > > properties of the user (user-level, default enteprise, etc.) and > > finally we have properties of the instance (informixserver, etc.) plus > > could be some combinations user+instance could have different user- > > level environment variable). > > > So we design a script that is called on the .profile of the user > > session, it gets username, netbios name of the terminal, and the > > instance the user could have several instances enabled so there is the > > 4GL program that picks up a instance. with those three elements we > > build the environment variables for the session as a script, save this > > to a file, then do a source (.) with the file. finally we get from > > environment variables the directory to go and the program to execute > > for the user. > > > Notice that the model is in informix tables and accessed by informix > > 4gl programs, prior the really get and build the user i4gl > > environment. > > > Of course this is that way because we have a LOT of informix 4gl > > programs that builds our ERP and more subsystems, the programs uses a > > lot envirnment variables and cant do a cut-point redesign of the > > systems, we are in a slow migration where i4gl coexists with .net > > services. > > > Hope you understand :) we are a complex mesh of technology and > > people... > > As others have said you can't set an environment variable and have it > passed back to the calling program. The Unix environment variable just > doesn't work like that. It's one-way. > > What you could do is build a command string in the 4GL program which > includes both setting the environment and executing the program for the > user. You would then run this command string from within the 4GL. This > would, of course, leave your existing 4GL program waiting for the user > program to execute. > > -- > Ian > > Hotmail is for spammers. Real mail address is igoddard > at nildram co uk
What I see is that you're painting yourself in to a corner. You can put static variables in to your .profile / .login etc ... shells that get started on launch. You could put a line in your .profile that calls a python script which connects to the database and sets up the current shell variables for the user. You could also try creating a .properties file that sits in cwd and when the Informix app starts, it can read the values in the .properties file to know where to connect and how. Or you can shift your paradigm and use an app server where you log in, and based on the log in, you can then get the correct permissions and access to the correct applications. Of course this means moving to a web / app environment. In sticking with your 4GL environment, I would suggest you look at using a scripting language like Python to help set up your environment dynamically and then from the shell, call the correct app. > From: eferreyra@gmail.com > Subject: Re: set environment variable > Date: Mon, 24 Nov 2008 04:39:15 -0800 > To: informix-list@iiug.org > > the thing is we are a corporation where there is several enterprises, > and (at least) each one have one informix online instance, anyway > there are several informix instances... > > With this scenario we have users that access several instances, but > this based on a permission scenario, not everybody access any informix > instance of course. > > So we need to put some own logic in the .profile of the users sessions > to app servers (i4gl app servers), we design a model where there are > properties of the terminals (printer name, POS number, etc.) and > properties of the user (user-level, default enteprise, etc.) and > finally we have properties of the instance (informixserver, etc.) plus > could be some combinations user+instance could have different user- > level environment variable). > > So we design a script that is called on the .profile of the user > session, it gets username, netbios name of the terminal, and the > instance the user could have several instances enabled so there is the > 4GL program that picks up a instance. with those three elements we > build the environment variables for the session as a script, save this > to a file, then do a source (.) with the file. finally we get from > environment variables the directory to go and the program to execute > for the user. > > Notice that the model is in informix tables and accessed by informix > 4gl programs, prior the really get and build the user i4gl > environment. > > Of course this is that way because we have a LOT of informix 4gl > programs that builds our ERP and more subsystems, the programs uses a > lot envirnment variables and cant do a cut-point redesign of the > systems, we are in a slow migration where i4gl coexists with .net > services. > > Hope you understand :) we are a complex mesh of technology and > people... > _______________________________________________ > Informix-list mailing list > Informix-list@iiug.org > http://www.iiug.org/mailman/listinfo/informix-list _________________________________________________________________ Proud to be a PC? Show the world. Download the “I’m a PC” Messenger themepack now. hthttp://clk.atdmt.com/MRT/go/119642558/direct/01/
On Mon, Nov 24, 2008 at 4:39 AM, eferreyra <eferreyra@gmail.com> wrote: > the thing is we are a corporation where there is several enterprises, > and (at least) each one have one informix online instance, anyway > there are several informix instances... > > With this scenario we have users that access several instances, but > this based on a permission scenario, not everybody access any informix > instance of course. > > So we need to put some own logic in the .profile of the users sessions > to app servers (i4gl app servers), we design a model where there are > properties of the terminals (printer name, POS number, etc.) and > properties of the user (user-level, default enterprise, etc.) and > finally we have properties of the instance (informixserver, etc.) plus > could be some combinations user+instance could have different user- > level environment variable). > > So we design a script that is called on the .profile of the user > session, it gets username, netbios name of the terminal, and the > instance the user could have several instances enabled so there is the > 4GL program that picks up a instance. with those three elements we > build the environment variables for the session as a script, save this > to a file, then do a source (.) with the file. finally we get from > environment variables the directory to go and the program to execute > for the user. > > Notice that the model is in informix tables and accessed by informix > 4gl programs, prior the really get and build the user i4gl > environment. > > Of course this is that way because we have a LOT of informix 4gl > programs that builds our ERP and more subsystems, the programs uses a > lot of environment variables and can't do a cut-point redesign of the > systems, we are in a slow migration where i4gl coexists with .net > services. Be very careful about controlling security with environment variables. It is too easy for people to work around them. -- Jonathan Leffler #include <disclaimer.h> Email: jleffler@earthlink.net, jleffler@us.ibm.com Guardian of DBD::Informix v2008.0513 -- http://dbi.perl.org/ "Blessed are we who can laugh at ourselves, for we shall never cease to be amused." NB: Please do not use this email for correspondence. I don't necessarily read it every week, even.
Related threads
- the longer you surf, the MORE $$$ you earn !!
- Store procedure
- emulation for Vt100
- extent size questions again ...