Page 1 of 1 1
Topic Options
#172649 - 2007-01-10 10:42 PM @ERROR giving false positives?
itdaddy Offline
Starting to like KiXtart

Registered: 2006-12-19
Posts: 145
Loc: Wisconsin
Code:
$ThisMyArray
 For Each $Element In $ThisMyArray "PC1", "PC2", "PC3"

	  tcGetEvent($Element, $Task)  ; load the bad task data
          tcDefineTask("SUS=0")        ; (disable = 1, enable = 0)
          tcSetEvent($Element, $Task)  ; update the task on the target
          IF @ERROR <> 0
	       $RC = REDIRECTOUTPUT (failure.txt, 0)
	       ? $Element
	  Else if @ERROR = 0
	        $RC = REDIRECTOUTPUT (success.txt, 0)
	       ? $Element
	  Endif Endif

 Next


Hey anyone or Glenn,

I got this to work thanks so much. But my error trap works on all my other scripts but for somereason @ERROR keeps giving me false positves (back and forth whether a 0 or 1). Why? and how can I correct this. I like and need to see which PCs failed and which succeeded. This is crucial. Thanks guys

Happy New you to you all!
_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin

Top
#172652 - 2007-01-10 11:16 PM Re: @ERROR giving false positives? [Re: itdaddy]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
actually, this:
Code:
$ThisMyArray
 For Each $Element In $ThisMyArray "PC1", "PC2", "PC3"


does not work at all.
your whole for-next loop is skipped.
_________________________
!

download KiXnet

Top
#172653 - 2007-01-10 11:19 PM Re: @ERROR giving false positives? [Re: itdaddy]
Benny69 Offline
Moderator
*****

Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
You have to define the array before you can use it:
Code:
$ThisMyArray = "PC1", "PC2", "PC3"
 For Each $Element In $ThisMyArray

	  tcGetEvent($Element, $Task)  ; load the bad task data
          tcDefineTask("SUS=0")        ; (disable = 1, enable = 0)
          tcSetEvent($Element, $Task)  ; update the task on the target
          IF @ERROR <> 0
	       $RC = REDIRECTOUTPUT (failure.txt, 0)
	       ? $Element
	  Else if @ERROR = 0
	        $RC = REDIRECTOUTPUT (success.txt, 0)
	       ? $Element
	  Endif Endif

 Next

_________________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)

Top
#172680 - 2007-01-11 08:01 AM Re: @ERROR giving false positives? [Re: Benny69]
itdaddy Offline
Starting to like KiXtart

Registered: 2006-12-19
Posts: 145
Loc: Wisconsin
yeah dudes; you are right; it was a type sorry my bad!

I was tired when I wrote that.!
THANKS!

DOES ANYONE KNOW WHY I am getting false positves? what i mean is.
I am not getting the correct error handling I am use to?
and it is not writing missed workstation names to the correct text file.
success.txt or failure.txt?
help
_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin

Top
#172682 - 2007-01-11 10:07 AM Re: @ERROR giving false positives? [Re: itdaddy]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
well, you are not showing what is $task

anyway, this:
Code:
          IF @ERROR <> 0
	       $RC = REDIRECTOUTPUT (failure.txt, 0)
	       ? $Element
	  Else if @ERROR = 0
	        $RC = REDIRECTOUTPUT (success.txt, 0)
	       ? $Element
	  Endif Endif

is same as:
Code:
          IF @ERROR <> 0
	       $RC = REDIRECTOUTPUT (failure.txt, 0)
	       ? $Element
	  Else
	        $RC = REDIRECTOUTPUT (success.txt, 0)
	       ? $Element
	  Endif
_________________________
!

download KiXnet

Top
#172687 - 2007-01-11 02:17 PM Re: @ERROR giving false positives? [Re: Lonkero]
Benny69 Offline
Moderator
*****

Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
The @ERROR macro only contains the most recent error code, you are only checking for an error after the third function you are calling, you should be checking after each one. It would be easier for us to help you if you post the ENTIRE script and not expect us to try to guess what is happening.
_________________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)

Top
#172690 - 2007-01-11 03:50 PM Re: @ERROR giving false positives? [Re: Benny69]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
Of the 3 functions, the third is the one that you would want to monitor the return code from. I'd suggest adding "@SERROR ?" statements (without quotes) after EACH function to see what's happening.

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

Top
#172741 - 2007-01-12 09:53 PM Re: @ERROR giving false positives? [Re: Glenn Barnas]
itdaddy Offline
Starting to like KiXtart

Registered: 2006-12-19
Posts: 145
Loc: Wisconsin
Code:
call "tcLib.kxf"

tcInit(1)

  ; just disable each PC on network
    $Task = "FSPinstall"


$ThisMyArray = "PC1", "PC2, "PC3"

For Each $Element In $ThisMyArray

	  tcGetEvent($Element, $Task)  ; load the bad task data
          tcDefineTask("SUS=0")       ; set it to Suspend (disable = 1, enable = 0)
          tcSetEvent($Element, $Task)  ; update the task on the target
         
	  IF @ERROR <> 0
	       $RC = REDIRECTOUTPUT (failure.txt, 0)
	       ? $Element
	  Else if @ERROR = 0
	        $RC = REDIRECTOUTPUT (success.txt, 0)
	       ? $Element
	  Endif Endif


 Next



Sorry, here it is and it works slick like (Glenn thanks). But it gives false positives and false negatives. I have this same error handling scheme for shell commands in Kixtart and it handles them correctly; I have tested it ushering failures to failure.txt and successes to success.txt. Could you explain a bit more on why (Glenn please)the errors traps are hit and miss. I think I understand what you say; can you detail it a bit more? Thanks
so much to you all for you help!
Thanks Jooel! Yeah, it is hard without entire code.

I made this cause i didnt want to go to each workstation behind the scense just to disable this task; script worked slick did what could have taken 1 hour took only 3 minutes! bam!!!!!!!!!! I love scripts!


Edited by itdaddy (2007-01-12 09:59 PM)
_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin

Top
#172749 - 2007-01-12 11:18 PM Re: @ERROR giving false positives? [Re: itdaddy]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
Try this:

Code:
; - Glenn - added debugging statements
; I don't indent debug code so I can remember it doesn't belong there!

call "tcLib.kxf"

tcInit(1)

; just disable each PC on network
$Task = "FSPinstall"

$ThisMyArray = "PC1", "PC2, "PC3"

$RC = RedirectOutput('c:\temp\status.log')

For Each $Element In $ThisMyArray

'PC is ' $Element ?

	  tcGetEvent($Element, $Task)  ; load the bad task data
'GetEvent returned: ' @SERROR ?
'Task Array contains:' ?
For $I = 0 to 20
  $I ' ' $a_tcTASK[$I] ?
Next

          tcDefineTask("SUS=0")       ; set it to Suspend (disable = 1, enable = 0)
'DefineTask returned: ' @SERROR ?
'Task Array contains:' ?
For $I = 0 to 20
  $I ' ' $a_tcTASK[$I] ?
Next

'Compare the before/after values! Enter to continue: ' Gets $ ?

          tcSetEvent($Element, $Task)  ; update the task on the target
  ; Need to capture the errors here, since RedirectOutput will change them!
  $EC = @ERROR
  $ES = @SERROR
'SetEvent returned: ' $ES ?


  $Element ' - ' $EC ' - ' $ES ?
 Next

$RC = RedirectOutput('')



Then examine the resulting log file to see what happened. You can even post it here.

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

Top
#172751 - 2007-01-12 11:22 PM Re: @ERROR giving false positives? [Re: itdaddy]
itdaddy Offline
Starting to like KiXtart

Registered: 2006-12-19
Posts: 145
Loc: Wisconsin
Code:
call "tcLib.kxf"

tcInit(1)

  ; just disable each PC on network
    $Task = "FSPinstall"


$ThisMyArray = "ftran1", "ftran2", "ftran3"

For Each $Element In $ThisMyArray

	  tcGetEvent($Element, $Task)  ; load the bad task data
          @SERROR ?
	  
	  tcDefineTask("SUS=0")       ; set it to Suspend (disable = 1, enable = 0)
          @SERROR ?
	  
	  tcSetEvent($Element, $Task)  ; update the task on the target
          @SERROR ?

	  ;IF @ERROR <> 0
	  ;     $RC = REDIRECTOUTPUT (failure.txt, 0)
	  ;     ? $Element
	  ; Else if @ERROR = 0
	  ;      $RC = REDIRECTOUTPUT (success.txt, 0)
	  ;     ? $Element
	  ; Endif Endif
sleep 30

 Next




Glenn, I did what you said and the message out was (The operation completed successfully). This means that @ERROR = 0 correct and if it @ERROR = 1 then it should say it failed. All three functions SUCCESSFUL?
So why doesn't this work well. It doesn't work. I tried it. With ftran2. I shut the workstation off to see if it would usher failed workstation names to the failure.txt? sometime its worked other times they all went into the failure.txt bucket even though all of them succeeded?

So why is it not doing what normally works in this scheme. It does work on my other script where it maps the drive and upon success or failure adds workstation names accordingly? thanks.

Yes, guys I know the error trap is commented out for a reason this time.
Thanks if you guys try to correct me. Thanks



Edited by itdaddy (2007-01-12 11:23 PM)
_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin

Top
#172754 - 2007-01-12 11:49 PM Re: @ERROR giving false positives? [Re: itdaddy]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
uhm. but you still keep the double "if" there?
horrifying.
_________________________
!

download KiXnet

Top
#172759 - 2007-01-14 12:25 AM Re: @ERROR giving false positives? [Re: Lonkero]
itdaddy Offline
Starting to like KiXtart

Registered: 2006-12-19
Posts: 145
Loc: Wisconsin
Jooel
what is so horrifying about that? It works on all my other applications
just perfectly. What is the big deal. if it works, then code it!
you can code anything different. that is what makes coding cool.
everyone has a style and i am just finding mine!

do you have any suggestions besides "horrifying?"

i guess you must be an expert error trapper!???

thanks
_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin

Top
#172760 - 2007-01-14 12:29 AM Re: @ERROR giving false positives? [Re: Glenn Barnas]
itdaddy Offline
Starting to like KiXtart

Registered: 2006-12-19
Posts: 145
Loc: Wisconsin
Thahks Glenn
I will try what you suggest! I will do it next week.
thanks a million!

hey i was thinking your pseudo name should be "rocket-man!"hahaah
that would be cool!

thanks
will get back to you here.
_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin

Top
#172761 - 2007-01-14 03:26 AM Re: @ERROR giving false positives? [Re: itdaddy]
Benny69 Offline
Moderator
*****

Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
itdaddy,
Don't piss Jooel off! He knows what he talking about, and i suggest you listen to his suggestions.
_________________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)

Top
#172762 - 2007-01-14 04:22 AM Re: @ERROR giving false positives? [Re: Benny69]
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
That code block can be cateogrized as 'horrifying' as it would indicate a lack of understanding of the IF-ELSE-ENDIF construct and functionality. The additional check for @ERROR=0 in the ELSE is superfluous as the only way to actually reach that area is if if 0 to begin with. Thus, the additional check adds absolutely no value. However, if one wants to write absolutely error-free code, then a SELECT-CASE-ENDSELECT would be more appropriate
Code:
SELECT
CASE @ERROR=0
; error is zero
CASE @ERROR<>0
; error is a non-zero value
CASE 1
; error is undefined or otherwise not matching properly
; this should never happen and would be an indicator of a rather catastrophic event
ENDSELECT



Edited by Sealeopard (2007-01-14 04:25 AM)
_________________________
There are two types of vessels, submarines and targets.

Top
#172763 - 2007-01-14 05:10 AM Re: @ERROR giving false positives? [Re: itdaddy]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Code:
If Not @ERROR
  $RC = RedirectOutPut('success.txt', 0)
  $Element ?
Else
  $RC = RedirectOutPut('failure.txt', 0)  
  $Element ?
Endif

Top
#172791 - 2007-01-15 05:21 PM Re: @ERROR giving false positives? [Re: NTDOC]
itdaddy Offline
Starting to like KiXtart

Registered: 2006-12-19
Posts: 145
Loc: Wisconsin
Benny69

Hey Bud, with comments like Jooel's below,
I don't care if your the President of the United States.

Quote:

uhm. but you still keep the double "if" there?
horrifying.


I am new to Kixtart. And I am not an expert programmer like you all.
But I want to get there. Sealeopard did a good thing by explaining
what horrifying meant. I can take slams, but just tell me where I am going wrong or why my code (sucks) isn't ethereal! But code is code sometimes; I have it in many other situations and it works well with NO errors. But I welcome all better code than what I produce that is why this forum is cool!

"Don't kick a baby down when he/she is trying to walk. Just clap for them for just walking even though it is wabbling!" Now noone tear up after I said this! hahahhaha!

Sealeopard,

thanks for the explain on horrifying!

NTDOC thank you as well for you help on my code!


happy new year!

Sealeopard, benny69 and Jooel,

Glenn knows what the traps are for or what I am trying to do.
In my other programs it works well. I am not checking errors twice for the sake of checking errors. I am sending computer names to two separate files.
failures.txt and success.txt. If no errors occur, send screen output which is $Element ? to success.txt and if errors occur, send screen output ($Element ?) or computer name of the action that failed to failure.txt.

So I can have a list of failures and successes for the next days evaluation . It has worked flawlessly in other programs that I have made. But I welcome any better code (I listen to anything you guys say that helps me and I hope I can help you out some day! Thanks guys!









Edited by itdaddy (2007-01-15 05:29 PM)
_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin

Top
#172812 - 2007-01-16 06:13 AM Re: @ERROR giving false positives? [Re: itdaddy]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
but I told you.
you just failed to listen.

if I got you awake with that comment, good.
but you shouldn't be all offended about that though.
_________________________
!

download KiXnet

Top
#172849 - 2007-01-16 10:01 PM Re: @ERROR giving false positives? [Re: Lonkero]
itdaddy Offline
Starting to like KiXtart

Registered: 2006-12-19
Posts: 145
Loc: Wisconsin
Jooel

did you explain why it was horrifying? i may have missed that?
which post explained why it was crappy code?

My eyes are terrible and sorry if i missed it.
And yes words like horrifying to a newbee are crushing
but I will take your feedback and try to better myself.
thanks a lot bud!

robert(aka itdaddy)

thanks for giving me your thoughts; provoking yes, and got the job done
no hard feelings my bad!!!!!dude! \:\)
_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin

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
1 registered (Allen) and 382 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.077 seconds in which 0.026 seconds were spent on a total of 13 queries. Zlib compression enabled.

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