Page 1 of 2 12>
Topic Options
#46327 - 2003-10-06 02:54 PM read value, perfom action, del value
nostradamus99 Offline
Fresh Scripter

Registered: 2003-10-06
Posts: 10
Hi,
Relativly new to kix and I desperately need this script to work.
I have a pcchange.log file like this:
pc-0001
pc-0002
pc-0003

The kix script needs to read this input file, perform an action (net use, set some xcals rights) and after that delete this value from the pcchange.log, then continue with pc-0002 etc. etc.
I found some scripts here on the forum and tried to put them together but of course this doesn't work.
This is what I had in mind:
Open (1, "pcchange.log")

$PCNAME = ReadLine(1)

While @ERROR = 0

? "$PCNAME is the machine which requires action, this should be performed about here?"

$PCNAME = ReadLine(1)

Copy "pcchange.log" "pcchange.bak"
Del "pcchange.new"
$rc = Open(2,"pcchange.log",2)
$rc = Open(3,"pcchange.new",5)
$LineIn=ReadLine(2)
$LineOut=$LineIn+Chr(13)+Chr(10)
While @ERROR = 0
If InStr($LineOut,"$PCNAAM")>0
$LineOut=""
EndIf

$rc = WriteLine(2,$LineOut)
$LineIn=ReadLine(2)
$LineOut=$LineIn+Chr(13)+Chr(10)
Loop
$rc = Close(2)
$rc = Close(3)
Del "pcchange.log"
Copy "pcchange.new" "pcchange.log"
Del "pcchange.new"

Loop

$ = Close (1)

:End
? End of inputscript

------------------
I get confused on where to loop the script and IF this is even possible.
If you have any tips to get this to work, please let me know...
Many thanks in advance...

[ 06. October 2003, 14:58: Message edited by: nostradamus99 ]

Top
#46328 - 2003-10-06 03:01 PM Re: read value, perfom action, del value
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
$rc = Open(2,"pcchange.log",2)
$rc = Open(3,"pcchange.new",5)
$LineIn=ReadLine(2)

here you will open the pcchange.log on every loop and read the first line.
which obviously is all the time the same.

$rc = WriteLine(2,$LineOut)

here you try to write to the same file, you opened for reading.
you probably ment something like:
$rc = WriteLine(3,$LineOut)
_________________________
!

download KiXnet

Top
#46329 - 2003-10-06 03:12 PM Re: read value, perfom action, del value
nostradamus99 Offline
Fresh Scripter

Registered: 2003-10-06
Posts: 10
Right!
Like I said, (one of the things) I get confused about is where to put the loop in.
Maybe I'm making this too difficult and there is an much easier way to get things done..

Please enlighten me... [Wink]

Top
#46330 - 2003-10-06 03:20 PM Re: read value, perfom action, del value
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
I think I might be able to write you working code but I ask instead you to work on the semi-code.

you already know what you want to do.

readline from the initial
loop while more lines
in the loop do the action
and probably write the results somewhere

like you see, you have at least one loop too much, one file too much.
yep, you go for too complex.

oh, and you should keep in mind that kixtart reads lines from starting of the file one by one.
so just taking of one line of the file and continuing the read is actually same as reading the line and copying every other line to new file and copy the new file on place of the old...
and re-open.
I don't think that is what you want to do [Wink]
_________________________
!

download KiXnet

Top
#46331 - 2003-10-06 04:02 PM Re: read value, perfom action, del value
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
if you use ReadFile(), do your work, validate, if complete add it to a complete log, if failed add to failed log... use WriteFile() for the output
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#46332 - 2003-10-06 04:18 PM Re: read value, perfom action, del value
nostradamus99 Offline
Fresh Scripter

Registered: 2003-10-06
Posts: 10
I'm one step further...
I created this:

Open (1, "d:\scripts\pcchange.log") = 0

While @ERROR = 0
$PCNAME = ReadLine(1)
? $PCNAME
?"connecting to $PCNAME...."
Shell '%Comspec% /e:1024 /c "net use \\$pcname /user:blabla"'
Sleep 2
---command to delete value from pcchange.log---
If $PCNAME=""
GoTo CloseIT
EndIf
Loop

:CloseIT
$ = Close (1)
GoTo End

:End
? "End of inputscript"

This works...what do I need to do to get the script to delete the $PCNAME from the pcchange.log?

Top
#46333 - 2003-10-06 04:19 PM Re: read value, perfom action, del value
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
code:
$PCList = readfile('c:\file.txt')

for each $PC in $PCList
whatever...
whatever...
whatever...
whatever...
if @error
$errlog=$errlog+'|'+$PC
else
$oklog =$oklog +'|'+$PC
endif
next

$=writefile('c:\file.err',split(substr($errlog,2),'|'))

$=writefile('c:\file.ok',split(substr($oklog,2),'|'))

_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#46334 - 2003-10-06 04:30 PM Re: read value, perfom action, del value
nostradamus99 Offline
Fresh Scripter

Registered: 2003-10-06
Posts: 10
My situation is as followes:
The pcchange.log file is my input file in the kix script and this file will constantly keep changing (more pc's being added to it).
So I dont want the script to do things twice, that's why I need the kixscript removing entries that are already done...I have another script running that makes sure that the pc doesn't get added twice...

Can this be done with what you have described above ?

Thanks for the supprt..

[ 06. October 2003, 16:31: Message edited by: nostradamus99 ]

Top
#46335 - 2003-10-06 04:35 PM Re: read value, perfom action, del value
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
I think that you would be better served by implementing a solution based on files (1 per computer) than a file containing many computers. This way you can selectively and easily delete the computers that have been processed. By moving the file to a "done" directory you can avoid having the computer processed a second time.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#46336 - 2003-10-06 06:18 PM Re: read value, perfom action, del value
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
just delete the pcchange.log and rename file.err
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#46337 - 2003-10-06 06:48 PM Re: read value, perfom action, del value
nostradamus99 Offline
Fresh Scripter

Registered: 2003-10-06
Posts: 10
Hi Radimus,

I'll try this tomorrow to see how this works out.

Howard:
I would like to implement such an solution but I would not know how. Some Admins here closed our W2K pc's (trough NTFS) so tight that I can't do much from our loginscript (like updating a few ini files [Mad] ) we have no AD so this is also a way I cant go.
With this script, I want to open up a few directories so that I can update my ini files and go on with my life [Wink]

Top
#46338 - 2003-10-06 06:55 PM Re: read value, perfom action, del value
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
FYI... readfile() and writefile() are UDFs
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#46339 - 2003-10-06 07:08 PM Re: read value, perfom action, del value
nostradamus99 Offline
Fresh Scripter

Registered: 2003-10-06
Posts: 10
Hmmm...UDF's...those are like addins right?

Do I need additional files for udf's to work, copy paste them and put them on top of the script..?
If it's to much info to explain, maybe a link to udf faq en readfile writefile addin?

Many thanks

[ 06. October 2003, 19:12: Message edited by: nostradamus99 ]

Top
#46340 - 2003-10-06 07:12 PM Re: read value, perfom action, del value
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
[Confused] See the FAQ Forum for FAQs!

You might also want to consider a .INI file instead of a text file. It'll make it much easier to do things based on computername as you just use the computername as section. This will also allow you to delete the complete section with just one line of KiXtart code.
_________________________
There are two types of vessels, submarines and targets.

Top
#46341 - 2003-10-06 07:14 PM Re: read value, perfom action, del value
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
www.gwspikval.com/jooel/UDF will give you alphabetical listing of korg-udfs.
check on the faq forum (alphabetical listing too) for "how to use UDFs"...
quess it's somewhere here:
http://www.kixtart.org/board/ultimatebb.php?ubb=forum;f=10;hardset=1000;start_point=25

[ 06. October 2003, 19:14: Message edited by: Lonkero ]
_________________________
!

download KiXnet

Top
#46342 - 2003-10-06 07:25 PM Re: read value, perfom action, del value
nostradamus99 Offline
Fresh Scripter

Registered: 2003-10-06
Posts: 10
Thanks,

I did look around before asking but all I could find was the UDF library...now I found it [Smile]
I'll try to use Radimus's suggestion if I get the UDF's to work [Big Grin]

Thanks...

Top
#46343 - 2003-10-11 12:48 AM Re: read value, perfom action, del value
nostradamus99 Offline
Fresh Scripter

Registered: 2003-10-06
Posts: 10
Hi,

I tried the UDF's but was unable to get it to work..had some difficulty understanding what the specified UDF's do and how they work. The standard kix commands are better documented. I know it's more work but he who is not smart will need more code I guess.

This is what I came up with..thought I'd post it so that some other starter might have some use for it. Thanks for all good and fast responses:

:Begin
;Shell '%Comspec% /e:1024 /c "net use X: /d"'
Shell '%comspec% /e:1024 /c d:\scripts\attrib.exe +R \\Server\Directory\pcchange.ini'
Open (1, "\\Server\Directory\pcchange.ini") = 0

While @ERROR = 0
$PCNAME = ReadLine(1)
? $PCNAME
?"connecting to $PCNAME...."
Use X: "\\$pcname\c$"
Sleep 1
Shell '%comspec% /e:1024 /c d:\scripts\xcacls.exe Path /t /c /g Everyone:c SYSTEM:f administrators:f /y '
Copy "d:\scripts\file.ini" "pathname"
Sleep 1
$versie = ReadProfileString ("pathname", "Version","version")
If $versie <> "1.4"
GoTo Writebad
Else
GoTo Writeini
EndIf
:Writeini
Shell '%Comspec% /e:1024 /c "net use X: /d"'
Open (3,Done.ini,5)
WriteLine(3,"$PCNAME " + @TIME + " " + @DATE + Chr(13) + Chr(10)) >nul
Close(3) >nul
GoTo Check
:Writebad
Shell '%Comspec% /e:1024 /c "net use X: /d"'
Open (4,Error.ini,5)
WriteLine(4,"$PCNAME " + @TIME + " " + @DATE + Chr(13) + Chr(10))
Close(4)
GoTo Check
:Check
If $PCNAME=""
GoTo CloseIT
EndIf
Loop

:CloseIT
$ = Close (1)
Shell '%comspec% /e:1024 /c d:\scripts\attrib.exe -R \\Server\Directory\pcchange.ini'
Del "\\Server\Directory\pcchange.ini"
Sleep 1
Open (5,"\\Server\Directory\pcchange.ini",1)
Sleep 1
Shell '%comspec% /e:1024 /c d:\scripts\xcacls.exe \\Server\Directory\pcchange.ini /t /c /g Everyone:rwe SYSTEM:f administrators:f /y '
Close(5)
GoTo End

:End
? "End of inputscript"

Top
#46344 - 2003-10-11 12:57 AM Re: read value, perfom action, del value
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
not sure what you try to do here but sure thing, it's not working.
you open ini-file like regular text-file but then you try to use readprofilestring() which syntax is also wrong.

now, if your file is ini, you don't need any kind of open close or readline nor writeline.
ini-files use writeprofilestring and readprofilestring.
_________________________
!

download KiXnet

Top
#46345 - 2003-10-10 01:32 PM Re: read value, perfom action, del value
nostradamus99 Offline
Fresh Scripter

Registered: 2003-10-06
Posts: 10
I'm sorry...but this script does work..I've used this script this morning and it has already updated 154 PC's! (I stopped checking manually if it DID work after checking about 25 pc's or so)

So please dont say it doesn't work. I've altered the script so that it doesn't show any of the files and paths I'm actually using...so it might be that pcchange.ini is actually pchange.txt
If you dont understand what I needed to do with this script, please read my first message at top!

Top
#46346 - 2003-10-10 03:14 PM Re: read value, perfom action, del value
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
I do not understand how you can clain that the UDFs are poorly documented. All UDFs follow the same exant header style as the build-in KiXtart functions/commnads. Additionally, the FAQ Forum contains extensive explanantions on how to use UDFs.

.INI files should/must be read via READPROFILESTRING as they are not ordinary text files and follow a very specific format.

You are using GOTOs in your code, which unfortunately prevents me from analyzing it. You also do not post code within [CODE] tags and don't use indentations, which also make it hard to read your code.
_________________________
There are two types of vessels, submarines and targets.

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 1574 anonymous users online.
Newest Members
BeeEm, min_seow, Audio, Hoschi, Comet
17882 Registered Users

Generated in 0.161 seconds in which 0.117 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