From: Greg Ercolano <erco@(email surpressed)>
Subject: Re: Automatically delete logs when dumping job?
   Date: Mon, 28 Jan 2008 12:13:00 -0500
Msg# 1670
View Complete Thread (7 articles) | All Threads
Last Next
Abraham Schneider wrote:
> Ok, sorry, think it was my confuse english :)
> 
> The syntax to start the script is clear and fine. But if I dump a
> specific job, normally I'd like to do something with the script that was
> rendered with this job.
> 
> So if I'd like to delete the log folder of this job, I have to tell my
> cleanup script, which log folder to delete. So how can I get the name of
> the actual log folder, script name, etc. inside my cleanup script

	I see.

	Yes, the dump script will be passed several environment variables
	that are useful for this.

   RUSH_JOBID -- The jobid for the job. With this, you can
                 you can invoke 'rush -ljf' to get all the info about the job.
                 So if you want the log directory, grep for the "LogDir:" line,
                 or if you want the submit command, grep for the "Command:" line.

   RUSH_LOGFILE -- The path to the logfile for the dump command itself, eg:
                   /some/path/logs/jobdumpcommand.log
                   If you chop off the filename part (jobdumpcommand.log),
                   you can derive the log directory, eg:

			my $logdir = $ENV{RUSH_LOGFILE};
			$logdir =~ s%/jobdumpcommand.log%%;
                        print "LOGDIR=$logdir\n";

	Use RUSH_LOGFILE to derive the log directory, as this will save
	you the trouble of having to invoke 'rush -ljf'.

	However, if you also want the path to the submitted script,
	then you can either parse that from the 'rush -ljf' output, eg:

            open(LJF, "rush -ljf|");
            my $submitpath = "";
            while ( <LJF> )
            {
                if ( /^\s+Command: perl (\S+)/ )    # get the submit script's path
                    { $submitpath = $1; }
            }
            close(LJF);
            print "SUBMITPATH=$submitpath\n";

	..or parse the jobinfo file that will be sitting in the
	log directory, eg:

            my $logdir = $ENV{RUSH_LOGFILE};
            $logdir =~ s%/jobdumpcommand.log%%;

            my $jobinfo_file = "$logdir/jobinfo";
            my $submitpath = "";
            unless ( open(JOBINFO, "<$jobinfo_file") )
                { die("$jobinfo_file: $!\n"); }
            while ( <JOBINFO> )
            {
                if ( /^\s+Command: perl (\S+)/ )    # get the submit script's path
                    { $submitpath = $1; }
            }
            print "SUBMITPATH=$submitpath\n";

	The latter is a bit longer, but prevents hitting the job server
	with the 'rush -ljf' request, accessing the file server to get
	the info instead.

> because there is no syntax like:
> 
> -nolog perl /path/to/your/cleanup.pl submitted_script logfile_dir

	You can do that if you want.. you can pass arguments to your
	cleanup script just that way. In the case of the above, you
	could access submitted_script and logfile_dir as $ARG[0] and $ARG[1]
	respectively.

	But I could see where you'd want logfile_dir to be automatically
	generated by the script at runtime, so it'd be best to use
	the RUSH_LOGFILE variable for that.

-- 
Greg Ercolano, erco@(email surpressed)
Seriss Corporation
Rush Render Queue, http://seriss.com/rush/
Tel: (Tel# suppressed)
Fax: (Tel# suppressed)
Cel: (Tel# suppressed)

Last Next