#187161 - 2008-04-22 04:39 PM
A script that will update variables in another script
|
ddady
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
|
|
|
|
#187165 - 2008-04-22 06:43 PM
Re: A script that will update variables in another script
[Re: Les]
|
ddady
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
|
|
|
|
#187170 - 2008-04-22 07:19 PM
Re: A script that will update variables in another script
[Re: Glenn Barnas]
|
ddady
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
|
|
|
|
#187172 - 2008-04-22 07:42 PM
Re: A script that will update variables in another script
[Re: ddady]
|
Glenn Barnas
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):
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:
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!
|
Top
|
|
|
|
#187185 - 2008-04-23 09:29 AM
Re: A script that will update variables in another script
[Re: Les]
|
ddady
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
|
|
|
|
#187190 - 2008-04-23 11:48 AM
Re: A script that will update variables in another script
[Re: ddady]
|
Richard H.
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:
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
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!
|
Top
|
|
|
|
#187257 - 2008-04-24 08:25 AM
Re: A script that will update variables in another script
[Re: Glenn Barnas]
|
ddady
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
|
|
|
|
#187265 - 2008-04-24 01:52 PM
Re: A script that will update variables in another script
[Re: Mart]
|
Glenn Barnas
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!
|
Top
|
|
|
|
#187348 - 2008-04-27 12:03 AM
Re: A script that will update variables in another script
[Re: Glenn Barnas]
|
ddady
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
|
|
|
|
#187350 - 2008-04-27 12:24 AM
Re: A script that will update variables in another script
[Re: Gargoyle]
|
ddady
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
|
|
|
|
#187357 - 2008-04-27 07:58 AM
Re: A script that will update variables in another script
[Re: Gargoyle]
|
ddady
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
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Allen)
and 286 anonymous users online.
|
|
|