Thank you for the response. The source follows. Note that I added the 
System.gc() calls recently. Does Rhino not report out of memory errors?

----------------------------------------------------------------------------------------------------
---------------------------------------------awstats.js---------------------------------------------
----------------------------------------------------------------------------------------------------
importClass(java.io.File);
importClass(java.io.FilenameFilter);

importClass(java.text.DateFormat);
importClass(java.text.SimpleDateFormat);

importClass(java.util.Arrays);
importClass(java.util.Calendar);
importClass(java.util.Comparator);
importClass(java.util.LinkedList)
importClass(java.util.List)

var hosts = new LinkedList();
hosts.add(HOST_1);
hosts.add(HOST_2);
hosts.add(HOST_N);

var fileFilter = new FilenameFilter() {

        dateFormat: new SimpleDateFormat("yyyy-MM-dd"),

        accept: function(dir, filename) {

                if (!filename.matches("access_[0-9]+-[0-9]+-[0-9]+\\.log"))
                        {
                        return false;
                        }

                var i = "access_".length;

                var j = filename.lastIndexOf(".log");

                try     {
                        var datetime = 
this.dateFormat.parse(filename.substring(i, j));

                        return !isToday(datetime);
                        }
                catch (x)
                        {
                        return false;
                        }

                return true;
                }
        };

var fileComparator = new Comparator() {

        compare: function(object1, object2) {

                if (isFile(object1) && isFile(object2))
                        {
                        return object1.getPath().compareTo(object2.getPath());
                        }

                return 0;
                }
        };

try     {
        var iterator = hosts.iterator();

        while (iterator.hasNext())
                {
                processHost(iterator.next());
                }
        }
catch (x)
        {
        print(x);
        }

printTimestamp();

/**
 *      For each host:
 *              1) Run AWStats using runCommand():
 *                      perl {awstats.pl} -config={host} -update
 *
 *              2) Determine the log file directory.
 *
 *              3) Run gzip on all log files matching access_yyyy-MM-dd.log 
except today.
 */
function processHost(host)
        {
        printTimestamp();

        print("Processing host \"" + host + "\".");

        var directory = new File("/usr/local/www/apache/logs/" + host);

        var files = directory.listFiles(fileFilter);

        Arrays.sort(files, fileComparator);
        
        print("Found " + files.length + " log files to process.");

        for (var i = 0; i < files.length; i++)
                {
                awstats(host, files[i]);

                gzip(files[i]);

                print((i + 1) + " of " + files.length + " files processed.");

                printTimestamp();

                print();
                }

        print();
        }

function awstats(host, logFile)
        {
        print("awstats(" + host + ", " + logFile.getCanonicalPath() + ")");

        var awstatsScript = 
"/usr/local/www/docs/tvtweb3/awstats/WEB-INF/cgi-bin/awstats.pl";
        
        var logresolvemergeScript = 
"/usr/local/www/docs/tvtweb3/awstats/WEB-INF/tools/logresolvemerge.pl";

        try     {
                return runCommand("perl", awstatsScript, "-config=" + host, 
"-update", "-LogFile=" + logFile.getCanonicalPath());
                }
        catch (x)
                {
                print(x);

                return 1;
                }
        finally
                {
                System.gc();
                }
        }

function gzip(file)
        {
        var filePath = "" + file.getCanonicalPath();

        print("gzip(" + filePath + ")");

        try     {
                return runCommand("gzip", "-v", filePath);
                }
        catch (x)
                {
                print(x);

                return 1;
                }
        finally
                {
                System.gc();
                }
        }

function isFile(object)
        {
        return "java.io.File".equals(object.getClass().getName());
        }

function isToday(datetime)
        {
        return toDate(datetime).equals(toDate(new Date()));
        }

function toDate(datetime)
        {
        var calendar = Calendar.getInstance();
        calendar.setTime(datetime);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);

        return calendar.getTime();
        }

function printTimestamp()
        {
        var dateFormat = new SimpleDateFormat("yyyy-MM-dd H:mm:ss.S a z");

        print("[" + dateFormat.format(new Date()) + "]");
        }
----------------------------------------------------------------------------------------------------
---------------------------------------------awstats.js---------------------------------------------
----------------------------------------------------------------------------------------------------

  _____  
From: Insane User [mailto:[EMAIL PROTECTED]
To: Matt Mann [mailto:[EMAIL PROTECTED]
Sent: Sat, 22 Mar 2008 15:48:44 -0400
Subject: Re: Rhino Exits Abruptly

  
  


Hi Matt,
Could show the source
list, it would be easier to consider options then.
Regards,Insane User

Matt Mann wrote:
  All,

I wrote a Rhino script that iterates through a set of Web server log files. A 
log analyzer is run on each file via runCommand() and the file is gzipped (also 
via runCommand()) after log analysis completes successfully. When I run the 
script, execution exits abruptly while analyzing a medium-to-large log file 
before all files are processed. I have try/catch blocks in various places in 
order to output any errors, but no exceptions are caught.

Does this behavior sound familiar to anyone? Any clues would be much 
appreciated.

Thanks,
Matt
_______________________________________________
dev-tech-js-engine-rhino mailing list
[EMAIL PROTECTED]://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino  
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino

Reply via email to