#198476 - 2010-04-28 05:52 PM
array reference out of bounds
|
umferbongi
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
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.
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
|
|
|
|
#198486 - 2010-04-28 07:11 PM
Re: array reference out of bounds
[Re: Allen]
|
umferbongi
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?
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
   
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:
With:
$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
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
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 661 anonymous users online.
|
|
|