Page 1 of 1 1
Topic Options
#198476 - 2010-04-28 05:52 PM array reference out of bounds
umferbongi Offline
Just in Town

Registered: 2010-04-28
Posts: 3
Loc: usa
Hello, I have an old script written by another admin that I no longer work with to read a text file and e-mail some info out. When I run it now it is getting the following error.

ERROR : array reference out of bounds!
Script: K:\scripts\Job_notify.kix
Line : 104

Here is part of the code

 Code:
Loop
$restart=0
$junk=open(1, "$outputdir\joblist.txt", 2)

;Check jobs run since last checktime for failures
$x=Readline(1)
Do
	$array3=split("$x", ",")
	$jobid=$array3[0]
	$type=$array3[1]
	$state=$array3[2]
	$status=$array3[3]
	$policy=$array3[4]
	$client=$array3[6]
	$starttime=ctime($array3[8],-$timezone)
	$endtime=ctime($array3[10],-$timezone)
	$runtime=$array3[9]
	$PlaceHolder=$array3[17]


It fails on $type=$array3[1] line. The source file it is reading looks like this.

 Code:
920257,17,3,0,,,,,1272459337,0000000215,1272459552,,,,,servername,,,100
920256,6,3,0,Catalog_HotBackup,Full_230AM,servername,servername,1272439957,0000002192,1272442149,L180_LTO3,0,35,0,servername,46940708,68704,100
920255,6,3,0,Catalog_HotBackup,Full_230AM,servername,servername,1272439814,0000000145,1272439959,L180_LTO3,2,7,0,servername,85562,7,100
920254,6,3,0,Catalog_HotBackup,Full_230AM,servername,,1272439800,0000000154,1272439954,,5,,,servername,,,100
920253,6,3,0,Catalog_HotBackup,-,servername,servername,1272439800,0000002349,1272442149,,1,35,0,servername,,,100


Anyone have ideas?

Top
#198477 - 2010-04-28 06:17 PM Re: array reference out of bounds [Re: umferbongi]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4572
Loc: USA
If I had to guess I'd say your path is not correct to the text file.

You can put ? @serror after your open to see if it is finding it.

Also, a better way of using Open is with if (see the manual or link in my sig for more)


 Code:
if open(1, $outputdir + "\joblist.txt", 2)=0
  ;Check jobs run since last checktime for failures
  $x=Readline(1)
  Do
	$array3=split("$x", ",")
	$jobid=$array3[0]
	$type=$array3[1]
.
.
.
endif
_________________________
(... better days ahead)

Top
#198486 - 2010-04-28 07:11 PM Re: array reference out of bounds [Re: Allen]
umferbongi Offline
Just in Town

Registered: 2010-04-28
Posts: 3
Loc: usa
Thanks for the info. I'm not a script-er/programmer at all, just trying to fix this existing thing.

I see there is a loop and an until statement in this script, how would one do the if statement for open with an until statement?

 Code:
Loop
$restart=0
$junk=open(1, $outputdir+ "\joblist.txt", 2)

;Check jobs run since last checktime for failures
$x=Readline(1)
Do
	$array3=split("$x", ",")
	$jobid=$array3[0]
	$type=$array3[1]
	$state=$array3[2]
	$status=$array3[3]
	$policy=$array3[4]
	$client=$array3[6]
	$starttime=ctime($array3[8],-$timezone)
	$endtime=ctime($array3[10],-$timezone)
	$runtime=$array3[9]
	$PlaceHolder=$array3[17]
	
	if "$jobid"<>"$lastjob"
		if $type="0" or $type="1"
			If $state="3"
				if $status="0" or $status="" or $status="190" or $status="191" or $status="150"
				else
					if $status="1"
						$junk=Writeline(8, "$client - $policy - Status: $status End time: $endtime" + Chr(13) + Chr(10))
					else
						$junk=Writeline(2, "$client - $policy - Status: $status End time: $endtime" + Chr(13) + Chr(10))
					endif
				endif
			else
				$junk=Writeline(3, "$jobid" + Chr(13) + Chr(10)) 
			endif
		endif
	endif
	$x=readline(1)
Until $jobid<=$lastjob

Top
#198493 - 2010-04-29 03:06 PM Re: array reference out of bounds [Re: umferbongi]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
The problem is that the script splits a line up into fields using "," as a delimiter and then tries to assign the fields to variables.

One or more lines do not have enough fields but the script doesn't check for this - it just assumes that everything will be OK and then crashes when the data is bad.

GIGO

There is not enough of the original script to safely offer you a full solution, but a simple work-around for the array bounds error is to replace:
 Code:
$array3=split("$x", ",")

With:
 Code:
$array3=split($x+",,,,,,,,,,,,,,,,,,", ",")

This just ensures that there are enough delimiters in the original string to avoid the abend. You will still need to look at the output to determine why the data has gone bad.

Top
#198507 - 2010-04-29 06:05 PM Re: array reference out of bounds [Re: Richard H.]
umferbongi Offline
Just in Town

Registered: 2010-04-28
Posts: 3
Loc: usa
Thanks! That worked. I just had to add a | to make blat email out the output file with a line break, too bad it actually adds the | to the line. The script is running like a charm.
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
0 registered and 584 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.058 seconds in which 0.031 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