Page 2 of 3 <123>
Topic Options
#171870 - 2006-12-21 10:09 AM Re: @error handling? and redirection to a text file (append) [Re: itdaddy]
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
You should read the kix2010.doc included in the KiX2010_453.zip package. It explains "Break", "@LOGONMODE" and all the switches used with "Copy".
Important to know is that in KiXtart, "Break" is per default "Off". This means that when you break a script, p.e. via Task Manager, your computer gets logged of. We (at least I) just presume this is wanted behaviour during Windows Logon.

Top
#171879 - 2006-12-21 04:44 PM Re: @error handling? and redirection to a text file (append) [Re: Witto]
itdaddy Offline
Starting to like KiXtart

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

thanks for all your help!

maybe witto really means "dude who is witty!" haahah
thanks again. i am going to try my new code tonight.
see you guys later.D
_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin

Top
#171881 - 2006-12-21 05:56 PM Re: @error handling? and redirection to a text file (append) [Re: itdaddy]
itdaddy Offline
Starting to like KiXtart

Registered: 2006-12-19
Posts: 145
Loc: Wisconsin
Code:
$FourthAveArray = "ftran1", "ftran2", "ftran3", "SPARE", 
"FACCTG8", "FACCTG1", "FACCTG2"


For Each $Element In $FourthAveArray
          
         
      	 $Time = @msec
	 copy c:\fspcopy\*.mdb "\\"+$Element+"\c$\fsp\mdb" /c /r
	 IF @ERROR <> 0
	    REDIRECTOUTPUT (failure.txt, 0)
	    ? $Element
	 Endif     
 	 $Time = @msec - $Time

	 
	 
	 
	 
	 ;Shell "net use z: \\" + $Element + "\c$"  
	 ;Shell "CMD.EXE /C copy c:\fspcopy\*.mdb z:\fsp\mdb /y"
	 ;Shell "CMD.EXE /C time /t"
	 ;Shell "net use z: /delete"
	 

Next


okay witto

what am i doing wrong i added your code and commented mine out
it wont run? did i type something wrong?
help
_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin

Top
#171883 - 2006-12-21 06:47 PM Re: @error handling? and redirection to a text file (append) [Re: itdaddy]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
My thoughts...

Code:
; initialize array of computer names
$FourthAveArray = "ftran1", "ftran2", "ftran3", "SPARE", "FACCTG8", "FACCTG1", "FACCTG2"

; enumerate the array
For Each $Element In $FourthAveArray
          
         ; Get the current millisecond count - not good as this is the MSec portion of the current minute
      	 ; $Time = @msec

         ; Get the current millisecond count - not good as this is the MSec portion of the current minute
      	 $Time = @TICKS

	; copy the source to dest - quotes were missing
	 ; copy c:\fspcopy\*.mdb "\\"+$Element+"\c$\fsp\mdb" /c /r

        ; with quotes, and spaces to improve readability - will still fail because "\c$\..." is
	; interpreted as a variable "$", which isn't defined. The strings is interpreted as
	; "\c\fsp...", which is not valid
	; copy "c:\fspcopy\*.mdb" "\\" + $Element + "\c$\fsp\mdb" /c /r


	; corrected copy string - better would be to use Chr(36), or SetOption("NoVarsInStrings", "On")
	copy "c:\fspcopy\*.mdb" "\\" + $Element + "\c$$\fsp\mdb" /c /r

	 IF @ERROR <> 0
	; best practice - enclose string in quotes - "append" is the default - not needed
	; also - capture the return codes, and close the redirection
	;    REDIRECTOUTPUT (failure.txt, 0)
	    $RC=RedirectOutput('failure.txt')
	; "?" is not a print statement - it's a CR/LF.. should come AFTER the message
	;    ? $Element
	    $Element ' - ' @SERROR ?
	    $RC=RedirectOutput('')
	 Endif     
	; get elapsed time for this process - corrected to use TICKS
 	 $Time = @TICKS - $Time


Next


Glenn


Edited by Glenn Barnas (2006-12-21 07:44 PM)
_________________________
Actually I am a Rocket Scientist! \:D

Top
#171884 - 2006-12-21 07:24 PM Re: @error handling? and redirection to a text file (append) [Re: itdaddy]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Originally Posted By: itdaddy
did i type something wrong?

You failed to wrap the string that is the first parm in quotes.

copy 'c:\fspcopy\*.mdb' '...
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#171885 - 2006-12-21 07:41 PM Re: @error handling? and redirection to a text file (append) [Re: Les]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
The bigger problem is use of "$" in a string, without NoVarsInStrings, or doubling of the "$". As we saw earlier this week, Doc showed that simple strings would work without quotes.. With the unescaped "$" in the string, it is mis-interpreted and the path will never be found.

An @SERROR should prolly be written to the error log so you know WHY it failed, no just WHERE.

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

Top
#171886 - 2006-12-21 08:37 PM Re: @error handling? and redirection to a text file (append) [Re: Glenn Barnas]
itdaddy Offline
Starting to like KiXtart

Registered: 2006-12-19
Posts: 145
Loc: Wisconsin
Glenn and Les

thanks for the help. i think i get it.
1. missing quotes
2. root of C: is looked at like it was variable
escape it out you instruct me; cool!
3. add the @SERROR to find specific error

right?
i will try these and see how it works.
thanks
;D
you guys are awesome
_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin

Top
#171891 - 2006-12-21 09:48 PM Re: @error handling? and redirection to a text file (append) [Re: Glenn Barnas]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Originally Posted By: Glenn Barnas
The bigger problem is use of "$" in a string


I dunno... the unquoted string would surely bring KiX to its knees as it tries to use the * operator on the first parm. Why does everyone think quotes are optional???
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#171895 - 2006-12-21 10:46 PM Re: @error handling? and redirection to a text file (append) [Re: Les]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
I never think quotes are optional (except - MAYBE - while golfing, but even that gives me the willies), but Doc just mentioned that unquoted strings usually work - that's all. Quoting the string is absolutely correct, and in my opinion, necessary.

For ITDaddy's benefit -

The "$" is the variable indicator in Kix - everything that follows it, letters, numbers, and some characters - forms a variable name. The "$" by itself is a legal variable name, often used as a "throw-away" var to catch return codes that aren't needed.

The process of converting variable names to their contents is called "variable expansion", and it - by default - occurs inside of strings. Most of us have decided that this is NOT a good thing, specifically for what you are experiencing here. You actually WANT a "$" inside the string, and not the content of a variable.

One way to do it is to "escape" the "$" by doubling it - Kix ignores variable expansion when it sees "$$" and simply puts a single "$" in its place. OK for "quick-n-dirty" scripts, but not for scripts that will see long-term use, or more advanced scripts.

A second form is the use of Chr(36), which is the "$" char. This always works, but is less obvious when debugging, or reading someone else's code.

What's preferred, and what you'll see in most of our scripts, is the command
$RC = SetOption('NoVarsInStrings', 'On')
This tells Kix to ingore the "$" inside of quoted strings (another reason ALL strings should be quoted). This is placed at the beginning of the script. Doing this will prevent any confusion of the "\\server\c$\folder" form of UNC paths.

There are other SetOption values that most of us use, and they force better programming habits by making you declare your vars before use and things like that. Get familiar with the basics of Kix first, then try turning on "Explicit" and see if you declared all your vars..

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

Top
#171896 - 2006-12-22 12:02 AM Re: @error handling? and redirection to a text file (append) [Re: Glenn Barnas]
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
Glenn,
AFAIK, C$ is interpreted as C$, and not as a variable, even when the option "NoVarsInStrings" is "Off". The difference is the $ at the end.
Code:
Break On
Dim $RC
$RC = Dir("\\"+@WKSTA+"\C$\*")
While $RC <> "" AND @ERROR = 0
	? $RC
	$RC = Dir()
Loop

But I also prefer to set "NoVarsInStrings" to "On".

Top
#171898 - 2006-12-22 12:48 AM Re: @error handling? and redirection to a text file (append) [Re: Glenn Barnas]
itdaddy Offline
Starting to like KiXtart

Registered: 2006-12-19
Posts: 145
Loc: Wisconsin
glenn
wow! spoken like a real teacher. very well said.
man you write really clear!

i understand. but my script Kitty (not kiddy; since i play with already built scripts and learn some code hee hee!) attempts worked
to do what i need it to do. but i am just learning kix
and have a faint history of learning programming some basic C++ some Fortran, some BASIC, and javascript. i am not a programmer by any means
but i like to play with scripts to learn for my job. and the scripts i have made have always worked. but this forum rocks!
and i do enjoy kix very much..
I am glad I have you dudes around!

Witto thanks to you to for your inputs!


hey glenn seeing your rocket buff you are
did you see on the TV some time ago those rocket buffs
were attempting to build the biggest hobbiest rocket (forgive my bad typing please) ever built and it flopped and then someone build a much smaller but still big rocket and it was so cool watching it blast off; i can see myself do that. cool! are you one of those guys going to build the biggest rockect every for a hobbiest! gosh they said combined it cost like 10,000 USD
and it was cool see the computer chips and modules on the rocket;
do you do that; i bet you program them yourself dont you.
thanks so much;
;D



Edited by itdaddy (2006-12-22 12:48 AM)
_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin

Top
#171900 - 2006-12-22 01:49 AM Re: @error handling? and redirection to a text file (append) [Re: Glenn Barnas]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Quote:
but Doc just mentioned that unquoted strings usually work


Not exactly what I said there Glenn, but close.

It would appear that SINGLE Unbroken strings for VARS is able to omit the quotes. I don't think that it should, but it does work and has since 3.6x so fixing it might break other stuff or current scripts.

Normal STRINGS still REQUIRE quotes or will potentially abend or at least alter the expected outcome of the script.


@ITDADDY
Yeah, Glenn is really good at code commenting, better than anyone else I've personally worked with before. He also goes out of his way to try to explain the code for those interested.


.

Top
#171919 - 2006-12-22 01:53 PM Re: @error handling? and redirection to a text file (append) [Re: Witto]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
Hmm - you are right.. although I seem to recall this being a problem in earlier versions (maybe 10+ years ago in the 16b version?) ;\)

Or maybe I'm just thinking of other languages where it is a problem. Still, it's best not to use Var_ID chars in strings. It won't be a problem in this specific example, but consider something like
Code:
$e=4
"C$e" ?

which produces C4 - a potentially explosive result. Just because a letter preceeds the "$" doesn't mean it won't get interpreted.

I have a picture hanging in my office - a guy using his laptop at a funeral. The caption says "just because you CAN doesn't mean you SHOULD!" Outside of KixGolf, it's a good rule for programming.

ITDaddy: I may come across like a teacher because it's hard to shake 15+ years teaching IT subjects, including Unix and MCSE. As for rocketry, it's a blast, but no where near that expensive. The average rocket costs about $200 to build (parts/paint/epoxy), and flies with a $100 flight computer (records altitude and speed, fires 2 ejection charges for parachute deployment), and my larger rockets sometimes use a $600 avionics package that transmits real-time flight telemetry, including speed, altitude, and GPS location. The motors cost between $30 and $150. All of these costs are one-time purchases of reusable items. Fuel for the motors can run between $2 and $200 per flight for the rockets that I fly, although there are larger rockets that are much more expensive to build and fly. I build in the winter and fly in the summer, rarely spend more than an average of $200/month on the hobby.

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

Top
#171937 - 2006-12-22 09:17 PM Re: @error handling? and redirection to a text file (append) [Re: Glenn Barnas]
itdaddy Offline
Starting to like KiXtart

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

thanks about the rocket stuff

NTDOC and Glenn

I know this is not a kix thing or maybe could be.
but is there a command line that can turn on and off job schedule?
not AT commands but say i have a job scheduled already but want say a program run by jobscheduler to execute the final command (pseudo code: shut self off)
is there??

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

Top
#171938 - 2006-12-22 09:29 PM Re: @error handling? and redirection to a text file (append) [Re: itdaddy]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Do you mean like NET STOP the task scheduler? Why not?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#171939 - 2006-12-22 10:06 PM Re: @error handling? and redirection to a text file (append) [Re: Les]
itdaddy Offline
Starting to like KiXtart

Registered: 2006-12-19
Posts: 145
Loc: Wisconsin
les
explain NET STOP will stop job schedular in windows
say a job i called FSPcopy.job??

can i start and stop job with NET STOP and is there a START?


====================================
Hey guys; hope this dont offend anyone but i dabble alittle in perl
and found this cool perl script we use for our mobile laptop to different
subnets;when our trainer goes from site to site she just clicks
on a separate batch i mad and walla new TCP setting to hook up to localized network; works slick as snot;enjoy!
Perl script that changes TCP gateway ip and dns by batch file
_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin

Top
#171940 - 2006-12-22 10:46 PM Re: @error handling? and redirection to a text file (append) [Re: itdaddy]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
No but Glenn has a slick tool for doing it. I'll let him explain or share the details.
Top
#171946 - 2006-12-22 11:55 PM Re: @error handling? and redirection to a text file (append) [Re: NTDOC]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
Net Stop will stop the task scheduler service, and affect all scheduled tasks. If you want to control individual task events, or even specific triggers of a selected task, the tcLib library will get the job done. It's posted here on KORG, but the latest version is available from my web site. It's too big to be easily maintained here.

tcLib consists of a KiX library of functions, and Microsoft's JT.exe. Once you place JT.exe into a folder in your PATH (like the Windows folder), just include the tcLib in your script and disabling (suspending) a task is as easy as:
Code:
tcInit()
tcDefineTask('taskname', 'SUS=1')
$RC = tcSetEvent('hostname', ' taskname')


One of the cool things about tcLib (and the task scheduler) is that you can define a task event without a trigger (time to run), and then use tcExecute('host', 'eventname') to run it with the defined credentials anytime you need to. This is how I implement a network-wide power shutdown process. Each system has a shutdown command, and a single system monitors the UPS array and invokes the scheduled task on the other systems to shut them down.

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

Top
#171951 - 2006-12-23 01:09 AM Re: @error handling? and redirection to a text file (append) [Re: Glenn Barnas]
itdaddy Offline
Starting to like KiXtart

Registered: 2006-12-19
Posts: 145
Loc: Wisconsin
so what you are saying Glenn is
i can have my foreach loop with the array list of PC names
and put variable names in place of hostname and keep the taskname the same.?


this is what i want to do; i have this setup.exe program that uses a /s switch for default install; there is no msi file for it.
and I dont want to use a zap file and have employees choose to install.
i leave the workstations on at night my script copies a new setup.exe
file to a folder called C:\Add\scripts and in there i have a install.cmd
i put in the local pc job schedular and run as Domain Admin on a schedule time period andthen it changes permission on some folders using CACLS command. i do this cause 3rd party msi installer packages i think are flacky
so i use batch commands and some kix and job schedualar and it works slick
but i want it to disable the install.job after it sets permissions with CACLS command.but i dont know how. so i can use this tcl library liek i say above?
just loop it and how do put a var in place of hostname? so i can run through each pc; i am goingto use my foreach arry filler loop like i had startedout with? GPO installer program are sweet and easy in GPO
but hard to find a full version one that really works and wil stay working when patches and updates are applied. you know. so i do it simple;
my motto is use whatyou got! once i have it setup it works great!
what you think?
_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin

Top
#171952 - 2006-12-23 01:13 AM Re: @error handling? and redirection to a text file (append) [Re: itdaddy]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
I thought you was MCSE 2000/2003 certified and you do that type of setup?

Boy your users could have FULL admin rights in no time with that method.

Just add a few commands of their own to the file. Boot from a Windows PE and take rights to that folder if needed. Then add or remove stuff as they see fit without you ever being the wiser.

Top
Page 2 of 3 <123>


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

Who's Online
2 registered (morganw, mole) and 414 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.076 seconds in which 0.025 seconds were spent on a total of 14 queries. Zlib compression enabled.

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