Page 1 of 2 12>
Topic Options
#187161 - 2008-04-22 04:39 PM A script that will update variables in another script
ddady Offline
Getting the hang of it

Registered: 2006-09-03
Posts: 98
Hi all,

Is it possible to have a script with GET command [for example] in order to let a user to enter the data of variables in another script or even better in the same script?

Thanks in Advance

Top
#187163 - 2008-04-22 05:31 PM Re: A script that will update variables in another script [Re: ddady]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Why don't you tell us what you are trying to achieve rather than how you are trying to achieve it.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#187165 - 2008-04-22 06:43 PM Re: A script that will update variables in another script [Re: Les]
ddady Offline
Getting the hang of it

Registered: 2006-09-03
Posts: 98
OK,

Well, i made a script that runs once a day on a server and checks if the free space on the local partition is less than what i have decided to be the minimum limit. If so, it sends a notification mail by BLAT.

Let say that this script's name is "CHECKDISK" and the script i'm looking for will be named "DATASCRIPT"

We are giving tech services to a large number of companies which their servers are different from company to company, i need to make some sort of script [DATASCRIPT] that will ask certain questions and will take the data such as [minimum disk size, email address to send from and to, mail relay name, etc] and that the DATASCRIPT will put it in the CHECKDISK script the values.

The DATASCRIPT will run only once in order to fill the necessary values in the CHECKDISK script

I hope i managed to explain myself

Top
#187167 - 2008-04-22 06:51 PM Re: A script that will update variables in another script [Re: ddady]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
You might want to consider using an INI file or the system registry to define your parameters. The "process" script reads the ini file or registry values at startup. The "configure" script asks the questions and sets the values in the INI or registry.

We do something similar with our utilities- we use INI files stored in a standard path location. Since this "standard location" can vary between customers, this location is defined in a System environment var called S_CONFIG. We also use a standard registry path - "HKLM\SOFTWARE\ITCG\product" (where "ITCG" is our company initials).

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#187170 - 2008-04-22 07:19 PM Re: A script that will update variables in another script [Re: Glenn Barnas]
ddady Offline
Getting the hang of it

Registered: 2006-09-03
Posts: 98
Ok, so from what i understand, i should creat an INI file and than run the CONFIGURE script which will add the values to the INI file and then the PROCESS script will read the values from the INI?

If so, how do i tell the CONFIGURE script what to write and where ,and more important how the PROCESS script will know which data to take from the INI?

Can you please give an example?

Top
#187171 - 2008-04-22 07:41 PM Re: A script that will update variables in another script [Re: ddady]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
If you create a default ini file and a so called configure script for each customer/task then you could fire up your configure script to set all or most variables in the ini file that are specific for that task or customer. The scripts used can then read stuff from the ini file using the ReadProfileString function and write back the result needed by an other script with the WriteProfileString function.
This way there is no need for sharing variables between two or more scripts and no scripting knowledge is necessary when setting up the task or changing things a bit one could just edit the ini file with a text editor.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#187172 - 2008-04-22 07:42 PM Re: A script that will update variables in another script [Re: ddady]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
Well, as an example from your CHECKDISK script..

you create a configure script - let's call it CDcfg.kix - it asks for the name of the email account to send mail to, and the name of the mail server.

Once it asks for and the user enters those values (and you potentially do some error checking, like verifying you can resolve the mail server name in DNS), you write the values to the config file (called CHECKDISK.ini):
 Code:
CLS
'Send mail to: ' Gets $MailUser ?
' Mail Server: ' Gets $MailServer ?
$ = WriteProfileString('%S_CONFIG%\checkdisk.ini', 'COMMON', 'MailUser', $MailUser)
$ = WriteProfileString('%S_CONFIG%\checkdisk.ini', 'COMMON', 'MailServer', $MailServer)

Of course, this assumes that you have properly defined the System environment var "S_CONFIG", and have created the path it refers to. This could be done by the process used to install this utility.

Your process script - CHECKDISK.KIX - would begin by loading its parameters:
 Code:
If Not Exist('%S_CONFIG%\checkdisk.ini')
  'ERROR: not configured!' ?
  Exit 2
EndIf
$MailUser = ReadProfileString('%S_CONFIG%\checkdisk.ini', 'COMMON', 'MailUser')
$MailServer = ReadProfileString('%S_CONFIG%\checkdisk.ini', 'COMMON', 'MailServer')

; rest of your script . . .

That's the basic idea - you will need to customize this to your specific needs.

Glenn


Edited by Glenn Barnas (2008-04-22 07:57 PM)
Edit Reason: missing param
_________________________
Actually I am a Rocket Scientist! \:D

Top
#187174 - 2008-04-22 08:31 PM Re: A script that will update variables in another script [Re: Glenn Barnas]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
You could GUIfy your config script with KiXforms or XLSInputBox() for a more professional look.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#187185 - 2008-04-23 09:29 AM Re: A script that will update variables in another script [Re: Les]
ddady Offline
Getting the hang of it

Registered: 2006-09-03
Posts: 98
Ok, I got the idea.

But i still don't understand the S_CONFIG thing and i will appreciate some explanation of how to work with it or configure it.

Regarding KiXforms, the commands look a lot like VB, is there any Drag&Drop GUI like VB?

Thanks in advance for all responses

Top
#187188 - 2008-04-23 09:48 AM Re: A script that will update variables in another script [Re: ddady]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
 Originally Posted By: ddady
Ok, I got the idea.

But i still don't understand the S_CONFIG thing and i will appreciate some explanation of how to work with it or configure it.
....


S_CONFIG is set as an environment variable. You can see them by typing SET in a command window. Actually it is %S_ CONFIG%. It will hold the default path where the app or script is stored. The script will reference that to get the path it should use.
Setting it can be done from a command window or with a kix script using the commands SET or SETM

 Originally Posted By: ddady

....
Regarding KiXforms, the commands look a lot like VB, is there any Drag&Drop GUI like VB?
....


Yes there is. It’s called kixforms designer. It lets you create the form and place all kinds of controls (buttons, checkboxes listviews, etc…) on it and it will create the code to display the form and its controls. You will have to create the action for lets say a button in a script editor.


Edited by Mart (2008-04-23 09:49 AM)
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#187190 - 2008-04-23 11:48 AM Re: A script that will update variables in another script [Re: ddady]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
If you keep your CONFIG script, PROCESS script and INI file in the same folder you can make things a little more simple and use the built-in macro @SCRIPTDIR to determine the location:
 Code:
CLS
'Send mail to: ' Gets $MailUser ?
' Mail Server: ' Gets $MailServer ?
$ = WriteProfileString(@SCRIPTDIR+'\checkdisk.ini', 'COMMON', 'MailUser', $MailUser)
$ = WriteProfileString(@SCRIPTDIR+'\checkdisk.ini', 'COMMON', 'MailServer', $MailServer)

@SCRIPTDIR is populated automatically with the path to the directory that the script is run from, so saves you the effort of setting an environment variable.

Top
#187193 - 2008-04-23 01:02 PM Re: A script that will update variables in another script [Re: Richard H.]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
Having scripts in multiple languages - Kix, Bat, & perl - the environment variable(s) allow me to place all scripts & utilities in one folder, and config files in another. Also allows me to apply different permissions to each folder, allowing authorized people to manipulate the config files but not the scripts.

On all servers and admin workstations at every client site, I create (via script) a /local and /local/bin folder structure. S_CONFIG defines the actual location of /local and S_BIN defines the /local/bin path. These are usually on C:. Kix32, some other utilities, and all kix/perl/bat scripts are in the /local/bin folder. Any config file is in /local. Scripts that need to call other scripts can reference $S_BIN%\scriptname, and config files are referenced by %S_CONFIG%\configfile.

A minor clarification of Mart's reply - the environment variable names are "S_BIN" and "S_CONFIG" - you can verify this by typing "set" at a command prompt. You reference or define the variable name by "VARNAME", but you reference its CONTENTS by "%VARNAME%".

Glenn

PS - the Customize script on my web site can be used to define these environment variables, create the folders, populate the folders with standard scripts, utilities, and script engines, and perform other basic configuration processes. It's all controlled by an ini file, so easily customized. I run it on all servers, and on the workstations of any system/network admin that needs access to the admin tools that it installs.
_________________________
Actually I am a Rocket Scientist! \:D

Top
#187257 - 2008-04-24 08:25 AM Re: A script that will update variables in another script [Re: Glenn Barnas]
ddady Offline
Getting the hang of it

Registered: 2006-09-03
Posts: 98
OK, Just when i thought that i'm starting to understand all this S_CONFIG thing, you guys manage to confuse me

I'm sorry to be a BB, but when i type SET at the command prompt i see a big list and there is no S_CONFIG. Should i create it? If so, than how and where?

I'm sorry but those things are not so obvious to me, and if i wont ask i will bever learn and know. I will appreciate some more "step by step" explanation if it possible.

P.S - if i create a kix file with KIXFORM DESIGNER, will it run on any machine even if it doesnt have the KiXforms.NET Development Build installed on it?

Top
#187259 - 2008-04-24 08:53 AM Re: A script that will update variables in another script [Re: ddady]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
You should create the environment variables. You can use the SET command from a command prompt or the SET, SETM or SETL build in commands in kix.

Type set /? at a command prompt to see all the options the Windows SET command has. The kix SET, SETM and SETL commands are all explained on page 46 and 50 of the 4.60 manual. There are differences. SETM for example requires access to HKEY_LOCAL_MACHINE that regular user do not have so it is choose your tool wisely.

As for the stuff created in KF designer. You need to install/register the Kixforms.NET or classic dll (depending on what version you are using) on each system you want to run it on.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#187265 - 2008-04-24 01:52 PM Re: A script that will update variables in another script [Re: Mart]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
S_CONFIG is what I use - it represents "System Config Folder" (which makes sense to me and my team). I also use S_LIB, which is where some external UDFs are kept - I don't use that too often now that I use KGen to generate my scripts. S_BIN is also defined, which represents the location for binaries - scripts, executables, and such that are not part of the core O/S.

This was meant to illustrate one method for defining a physical location for storage of config data, and a process for informing all scripts / programs of any language where their config files could be found. You can use any name that suits you, just be consistent.

When you install your utilities, you create the folder where they will be stored, along with the config subfolder, and then you define the SYSTEM environment variable(s) that identify the location(s). 99% of the time, it will be the same place (which might lead you to hard-code the path into your scripts - very bad!). The use of the environment var lets you easily handle the exceptions - Citrix servers come to mind, since they usually have no C: or D: drives themselves.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#187348 - 2008-04-27 12:03 AM Re: A script that will update variables in another script [Re: Glenn Barnas]
ddady Offline
Getting the hang of it

Registered: 2006-09-03
Posts: 98
Sorry for the late response.

Ok, after looking in the command prompt and from your explanations.

If i write: SET [S_CONFIG=[c:\]] in the command prompt, It will configure the S_CONFIG folder in C directory?

Is Richard's way can save me the confusion of the SET thing?

Top
#187349 - 2008-04-27 12:15 AM Re: A script that will update variables in another script [Re: ddady]
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
Set is for enviromental variables ex: %systemdrive%, %path%, etc...
This does not configure a folder for you, but references one that is there already.

As an example:

At corporate headquarters
%PriServer% = SCorp
%AppServer% = SA_Corp

At a field office
%PriServer% = SFieldA
%AppServer% = SA_FieldA

At another field office
%PriServer% = SFieldB
%AppServer% = SA_FieldB

Now in my script I can just reference %PriServer% and use it to map everyones home drive to \\%PriServer%\Users$\Home\%UserName%

Or I need to launch a special application

Run \\%AppServer%\RunAtStart\WeAreWatching.EXE

So no matter where my servers are or what they are named I know that I have variable that I can use as a constant in my script.

Did that help any?
_________________________
Today is the tomorrow you worried about yesterday.

Top
#187350 - 2008-04-27 12:24 AM Re: A script that will update variables in another script [Re: Gargoyle]
ddady Offline
Getting the hang of it

Registered: 2006-09-03
Posts: 98
So,you're saying that i should create a folder with the name S_CONFIG in C drive and put all the script inside [in my situation the INI file and scripts CONFIG and PROCESS] and than in the command prompt will type
SET %S_CONFIG% = c:\

That will solve my problem?

Top
#187353 - 2008-04-27 02:48 AM Re: A script that will update variables in another script [Re: ddady]
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
It really depends on your deployment method.

You mention that this is for multiple clients, I would assume that each enviroment is independent (unable to talk to each other or to a central site).

If you can explain what the deployment model would look like we can help you decide the best method for setting up variables and having constincy at the same time.
_________________________
Today is the tomorrow you worried about yesterday.

Top
#187357 - 2008-04-27 07:58 AM Re: A script that will update variables in another script [Re: Gargoyle]
ddady Offline
Getting the hang of it

Registered: 2006-09-03
Posts: 98
OK!

A little background; I work in a company that gives IT services to about 50 companies. I made a script that should run only on those companies servers and that will notify us by mail [BLAT] if those servers free hard disks space is less than 10% from it's all capacity.

To make it easier let call this script "PROCESS", and the other script i'm looking to write will be "CONFIG".

Now, the script [PROCESS] run just fine, i have tested it on one company. Since every company has its own mail server, i was looking for an easier way to make the changes, such as: mail server name, mail sender address, etc. Instead of making those changes manually in the script [PROCESS],
The idea i had is to have another script [CONFIG] that will run only once in each company by our technicians and will ask them for the relevant information and will make those changes in the script [PROCESS] that will run by schedule one or twice a day.

Some of the solutions i have received here were by using an INI file and configure an enviroment variable with SET command that can be done from the script too.

Everything is clear to me [thanks to everybody here] but i can't realy understand how to do it. How to set this variable, how to write it, what the exact syntax? It doesnt matter that i will use this method on each and every company, i intend to make this SET thing by kix.

I hope that this will help you guys to help me :-)

p.s.

You guys doing a great job :-)

Top
Page 1 of 2 12>


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 262 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.073 seconds in which 0.027 seconds were spent on a total of 15 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org