Page 1 of 1 1
Topic Options
#120207 - 2004-05-26 08:51 PM Prechecking for a label
Pat Offline
Lurker

Registered: 2004-05-26
Posts: 3
Is there a way to precheck for a label before using the GOTO command. If the label does not exist the script just errors out. Or is there a way to have it continue on with the script like 'On Error Resume Next'

e.g.
goto MYLABEL
:MYLABEL
?"This works, but if MYLABEL didn't exist this would fail right out of the script."





Top
#120208 - 2004-05-26 08:55 PM Re: Prechecking for a label
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Hi Pat and welcome to the board.

In general I think you will find most users prefer not to use the GOTO for coding.

Can you please post what version of KiXtart you're using and what it is you want to do. I'm sure we can suggest a better method to get around using the GOTO coding style.

Or post your code (using the UBB Tags to keep the code formatting intact) and we'll check it out for you.

Top
#120209 - 2004-05-26 09:42 PM Re: Prechecking for a label
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
The simple answers to your questions are, no. There is no way to pre-check for a goto label. There is no "On Error Resume Next," which is reserved for inferior scripting languages.
Top
#120210 - 2004-05-26 10:34 PM Re: Prechecking for a label
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
I totally agree with Doc about not using GOTO, and I have to wonder why this kind of error would not be found when you are testing the script, but none the less here is an idea if you REALLY want to do it this way. I do not remember what version of kix started support of UDFs but I believe you have to have kixtart version 4.x to use the function below.

Code:
  
break on
$=setoption("WRAPATEOL","ON")


$sectionlabel="SectionTwo"
if labelexist($sectionlabel)
? "Found Label"
goto $sectionlabel
else
? "Didn't find Label"
exit
endif


exit
:SectionTwo
? "Exiting"




Code:

function labelexist($label)
dim $fh, $line
$labelexist=0
$fh=freefilehandle()
if open($fh,@scriptdir + "\" + @scriptname)=0
$line=readline($fh)
while @error=0 and $labelexist=0
if ucase(":" + $label)=ucase($line)
$labelexist=1
endif
$line=readline($fh)
loop
$=Close($fh)
endif
endfunction




Top
#120211 - 2004-05-26 11:32 PM Re: Prechecking for a label
Pat Offline
Lurker

Registered: 2004-05-26
Posts: 3
First of all, as a programmer I agree that “On Error Resume Next” is a last resort and usually hides bugs that should be fixed. We just had a recent problem that needed a quick fix until we could audit our scripts.

We're using v4.22 of Kixtart.

We have a large user/server base and we've divided up the drive mapping scripts into several sub scripts based on the server they generally map most of the drives to. This was done for speed and manageability.

Unfortunately we inherited this design from contractors during a conversion and for the most part this has worked great for us for years, but it does have the problem if the @USERID doesn’t show up as a label it errors out.

If we can use something other than goto without radically changing the design, I’m all for it.

Here’s a sample of our user drive mapping script….

So each user drive mapping script is in the format:

GOTO "@USERID"
RETURN

; Some User
:someuser
SHELL "NET USE P: \\someserver\share"
SHELL "NET USE S: \\anotherserver\SHARED"
RETURN

; Another User
:anotheruser
SHELL "NET USE P: \\someserver\share"
SHELL "NET USE S: \\anotherserver\SHARED"
RETURN

;etc
;etc

Top
#120212 - 2004-05-26 11:35 PM Re: Prechecking for a label
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Maybe I'm missing something here.

Why not just do an IF INGROUP call and map accordingly?

Top
#120213 - 2004-05-26 11:39 PM Re: Prechecking for a label
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX


ouch.... that has got to be a pain to keep up with!!

I would suggest that you use a INI file if you want to keep indivual user drive mappings, using readprofilestring() would give you better error handling.

but.... if it was me. I would rewrite it.

Top
#120214 - 2004-05-27 12:19 AM Re: Prechecking for a label
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
Ick... but I understand your problem better now.

You could use the labelexist function with just a small modification to your script...

Code:

if labelexist(@userid)
GOTO "@USERID"
else
RETURN
endif

; Some User
:someuser
SHELL "NET USE P: \\someserver\share"
SHELL "NET USE S: \\anotherserver\SHARED"
RETURN

; Another User
:anotheruser
SHELL "NET USE P: \\someserver\share"
SHELL "NET USE S: \\anotherserver\SHARED"
RETURN

;etc
;etc


Top
#120215 - 2004-05-27 12:29 AM Re: Prechecking for a label
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Sorry, but I still fail to see what is wrong with IF INGROUP and I don't see a need for SHELL to map a drive. KiXtart can do that as well.
Top
#120216 - 2004-05-27 12:52 AM Re: Prechecking for a label
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
You dont even need to check for a group really....WHy not just do IF/Endifs's for each user?

Code:

; Some User
If @UserID = "someuser"
USE P: "\\someserver\share"
USE S: "\\anotherserver\SHARED"
Endif

; Another User
If @UserID = "anotheruser"
USE P: "\\someserver\share"
USE S: "\\anotherserver\SHARED"
Endif


Top
#120217 - 2004-05-27 01:36 AM Re: Prechecking for a label
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
As many IFs as users... Yuck

...and I thought GOTOs were bad.

An INI file is the way to go if you insist on per-user settings.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#120218 - 2004-05-27 03:08 AM Re: Prechecking for a label
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Quote:

First of all, as a programmer I agree that “On Error Resume Next” is a last resort




Well as a LAN/WAN Admin of a World wide organization, I really can not support some of these other ideas.

Okay, so you took over the mess left by someone else. Hey I think many of us have done that. So now is the time for you to work on cleaning up the mess so that your job is easier in the long run and things run more smoothly.

I'm not much of an advocate of the Admin handling all the share mappings for users, but hey, maybe a few.

So even if this script is LONG, take a couple hours or a couple of days and modify it to a cleaner better managed script.

Create your Global Groups in your Domains and then place your users from those Domains into their Global Groups, then place your Global Groups into Universal Groups and apply your ACL to your resources with those Universal Groups. Then you'll be able to much more easily mange all of your resources, including drive mappings.

Taking a couple or a few hours of typing now will save you hours/days of trouble in the future.


ps. Don't nest groups too much or you may find it difficult to remove rights for someone further down the road as well. Maybe 2 to 3 nestings at most would be my recommendation.


Edited by NTDOC (2004-05-27 03:18 AM)

Top
#120219 - 2004-05-27 06:45 AM Re: Prechecking for a label
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
Oh, and what's the problem with searching the text file for the label in e.g. Notepad?
_________________________
There are two types of vessels, submarines and targets.

Top
#120220 - 2004-05-27 02:36 PM Re: Prechecking for a label
Pat Offline
Lurker

Registered: 2004-05-26
Posts: 3
We also use the IF INGROUP function as well. We map drives based on Group, then we map drives based on users. The drive mappings based on users is the one that has issues.

The use of SHELL to map the drives is because the USE statement puts generic names for the drive shares that have long share names.


Edited by Pat (2004-05-27 02:56 PM)

Top
#120221 - 2004-05-27 05:10 PM Re: Prechecking for a label
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
Get this UDF GetINI()

make a INI file like this and put it in your netlogon share with the logon script.
Code:

[bsmith]
f: = \\server\share
g: = \\server2\share
h: = \\another server\a share
[blindsay]
h: = \\flag-fs01\c$
i: = \\flag-fs01\e$



and you can replace every GOTO @user id with just this.

Code:

$drives = getini(@scriptdir + "\test.ini",@userid)
for each $map in $drives
$map = split($map,",")
use $map[1] $map[2]
next



if it comes up against a @USERID that does not exist, you can check @error but the script will not bomb on you.

Bryce

Top
#120222 - 2004-05-27 10:03 PM Re: Prechecking for a label
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
I agree with Bryce's .INI idea if you really must.

But the idea of individual micromanagement of users is not something I'd like to do.

Top
#120223 - 2004-06-03 05:41 PM Re: Prechecking for a label
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
So many suggestions and no response if any of them helped... I wish there was better follow-up responses by those asking the questions.
Top
Page 1 of 1 1


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

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

Generated in 0.05 seconds in which 0.017 seconds were spent on a total of 12 queries. Zlib compression enabled.

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