Page 1 of 1 1
Topic Options
#188718 - 2008-07-12 08:21 PM permanent running script suddenly terminates
cj_LHM Offline
Just in Town

Registered: 2008-07-12
Posts: 2
Hi all,

I have a problem with a script that is observing a directory. This program is running permanently on a server, but sometimes (after days or weeks) it terminates. Is there a way to find out why it stops?

This is a part of the script:

 Code:
IF EXIST ($lokal + "*.br*")
	  $FileName = Dir($lokal + "*.br*")

          While $FileName <> "" and @ERROR = 0

          ? $FileName
	  $Result = GetFileSize($lokal + $FileName)
          ? $Result

	  if $Result > 0
		copy $lokal + $FileName $lokal1 + $FileName
		copy $lokal + $FileName $lokal2 + $FileName
		copy $lokal + $FileName $lokal3 + $jahr + "\" + $FileName
		move $lokal + $FileName $remote + $FileName
	  endif

	  $FileName = Dir()

	  Loop

	endif


Thanks in advance

Carsten


Edited by Allen (2008-07-12 11:00 PM)
Edit Reason: added code tags

Top
#188719 - 2008-07-12 11:23 PM Re: permanent running script suddenly terminates [Re: cj_LHM]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4572
Loc: USA
I would have to guess, since you do not say, that this folder is semi/constantly having files added. I think the first time you run DIR it takes something like a snap shot of the files in the directory, and then on each new dir() give you the next. The problem is, if you keep adding files, it has no idea you have added them. Eventually, it runs out of files and the While $FileName <> "" kicks it out of the loop. I think since you are moving the files, a quick fix is to just change this line

$FileName = Dir()
to this:
$FileName = Dir($lokal + "*.br*")

You might consider adding some logging to see exactly what it is doing, and also maybe using DIRPlus() found here on the board.
_________________________
(... better days ahead)

Top
#188720 - 2008-07-13 03:53 AM Re: permanent running script suddenly terminates [Re: Allen]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
Your script is not "permanently running" - it runs until an error occurs or no filename is returned. What you need instead is a permanent loop - here's a simple example:
 Code:
$Path = 'C:\logfolder\'
$FileSpec = $Path + '*.log'

While 1 ; loop forever
 ; look for files
 $File = Dir($FileSpec)
 ; do stuff if we have files
 If $File
  ; loop here for all the files
  While Not @ERROR
   Move $Path + $File 'D:\LogArchive\'
   $File = Dir()
  Loop ; end of file process loop - error thrown when no more files
 EndIf

 ; Now wait a little while before checking again to reduce overhead
 Sleep 15 ; 15 to 120 seconds, depending on frequency & quantity of new files

Loop ; end of Loop Forever

The article in the "script vault" that illustrates exactly how to look for files, and run Kix as a service. I use this method and have many Kix based services running constantly.

Glenn

PS - this is an untested example to illustrate the difference between looping forever in the outer loop and looping while files are present in the inner loop.
_________________________
Actually I am a Rocket Scientist! \:D

Top
#188722 - 2008-07-13 11:44 AM Re: permanent running script suddenly terminates [Re: Glenn Barnas]
cj_LHM Offline
Just in Town

Registered: 2008-07-12
Posts: 2
Thanks for the quick answers.

I will test your examples.

Carsten

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 1607 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.056 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