#46327 - 2003-10-06 02:54 PM
read value, perfom action, del value
|
nostradamus99
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
|
|
|
|
#46329 - 2003-10-06 03:12 PM
Re: read value, perfom action, del value
|
nostradamus99
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...
|
Top
|
|
|
|
#46331 - 2003-10-06 04:02 PM
Re: read value, perfom action, del value
|
Radimus
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
|
Top
|
|
|
|
#46332 - 2003-10-06 04:18 PM
Re: read value, perfom action, del value
|
nostradamus99
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
   
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),'|'))
|
Top
|
|
|
|
#46334 - 2003-10-06 04:30 PM
Re: read value, perfom action, del value
|
nostradamus99
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
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.
|
Top
|
|
|
|
#46336 - 2003-10-06 06:18 PM
Re: read value, perfom action, del value
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
just delete the pcchange.log and rename file.err
|
Top
|
|
|
|
#46337 - 2003-10-06 06:48 PM
Re: read value, perfom action, del value
|
nostradamus99
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 ) 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
|
Top
|
|
|
|
#46338 - 2003-10-06 06:55 PM
Re: read value, perfom action, del value
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
FYI... readfile() and writefile() are UDFs
|
Top
|
|
|
|
#46339 - 2003-10-06 07:08 PM
Re: read value, perfom action, del value
|
nostradamus99
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
|
|
|
|
#46342 - 2003-10-06 07:25 PM
Re: read value, perfom action, del value
|
nostradamus99
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 I'll try to use Radimus's suggestion if I get the UDF's to work
Thanks...
|
Top
|
|
|
|
#46343 - 2003-10-11 12:48 AM
Re: read value, perfom action, del value
|
nostradamus99
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
|
|
|
|
#46345 - 2003-10-10 01:32 PM
Re: read value, perfom action, del value
|
nostradamus99
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
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 1574 anonymous users online.
|
|
|