SoftTree Technologies SoftTree Technologies
Technical Support Forums
RegisterSearchFAQMemberlistUsergroupsLog in
Global find & replace in job database

 
Reply to topic    SoftTree Technologies Forum Index » 24x7 Scheduler, Event Server, Automation Suite View previous topic
View next topic
Global find & replace in job database
Author Message
barefootguru



Joined: 10 Aug 2007
Posts: 195

Post Global find & replace in job database Reply with quote
I wrote a quick & dirty JavaScript job to do a global find & replace on the job database. I'm posting it because it might be useful for someone else.

It's only had basic testing. Usual caveats: use at your own risk, backup your database before running, etc.

Code:

// 2008-07-03 Tom Robinson <http://www.tomrobinson.co.nz/>

// Note to set job properties this job needs to not run as a 'Detached process'

//var property='COMMAND';
//var from='sasbatch.bat @'+'V"env:HSProgs"\\MH\\sasprogs\\';
//var to  ='sasbatch.bat @'+'V"env:HSProgs"\\Reporting\\HealthStat\\MH\\sasprogs\\';
   // Note splitting the @V so 24x7 doesn't interpret it here

var property='NAME';
var from='Management Weekly Reports ';
var to  ='Management Weekly ';

Scheduler.logAddMessage('INFO', @V"job_id", '@V"job_name"', 'Searching '+property+" property for '"+from+"' and replacing with '"+to);

var i=0;
for (i=1; i < 1000; i++) {  // Assume won't be more than 1,000 jobs defined
   try {
      var id=Scheduler.getJobProperty(i,'ID');
   }
   catch (error) {
      var id='';
   }

   if (id > '')
   {
      var oldvalue=Scheduler.getJobProperty(i,property);

      var ind=oldvalue.indexOf(from);
      // Scheduler.logAddMessage('INFO', @V"job_id", '@V"job_name"', 'i=' +i+' oldvalue='+oldvalue+' ind='+ind);

      if (ind > -1)
      {
         var newvalue=oldvalue.slice(0,ind);                     // Beginning (could be null)

         var newvalue=newvalue+to;                               // New middle

         var newvalue=newvalue+oldvalue.slice(ind+from.length);  // End (could be null)

         Scheduler.logAddMessage('INFO', @V"job_id", '@V"job_name"', 'Changing job '+i+" to '"+newvalue+"'");

         Scheduler.setJobProperty(i,property,newvalue);  // Comment this line to run through without changing anything
      }
   }
}

Wed Jul 09, 2008 9:13 pm View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7849

Post Reply with quote
Very nice. Thank you!
Thu Jul 10, 2008 5:35 pm View user's profile Send private message
seanc217



Joined: 23 May 2007
Posts: 272

Post Reply with quote
Hi,

So if I wanted to use the script to replace the agent name on all of my jobs in the database what would be the property I would be looking for?

Thanks.
Mon Nov 10, 2008 7:01 pm View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7849

Post Reply with quote
AGENT
Mon Nov 10, 2008 7:07 pm View user's profile Send private message
barefootguru



Joined: 10 Aug 2007
Posts: 195

Post Reply with quote
See also the 'Job Properties in JDL Format' section in the 24x7 JavaScript Reference
Mon Nov 10, 2008 7:55 pm View user's profile Send private message
seanc217



Joined: 23 May 2007
Posts: 272

Post Reply with quote
Hi I am trying to run this job to replace the agent globally.
However I am getting an error that says, "Error Accessing Database:4"

Any ideas?

Thanks.
Tue Nov 11, 2008 11:56 am View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7849

Post Reply with quote
I guess you run this as a detached job. If this is the case, please set it to non-detached mode because this job needs to update the job database file and modify other jobs.
Tue Nov 11, 2008 12:04 pm View user's profile Send private message
seanc217



Joined: 23 May 2007
Posts: 272

Post Reply with quote
I did uncheck detached and I receive the same error.
Tue Nov 11, 2008 12:13 pm View user's profile Send private message
seanc217



Joined: 23 May 2007
Posts: 272

Post Reply with quote
I got it to work, It look like it was still trying to run in detached mode.

Thanks!
Tue Nov 11, 2008 12:23 pm View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7849

Post Reply with quote
Oh good. Thanks for the status update.
Tue Nov 11, 2008 12:25 pm View user's profile Send private message
Display posts from previous:    
Reply to topic    SoftTree Technologies Forum Index » 24x7 Scheduler, Event Server, Automation Suite All times are GMT - 4 Hours
Page 1 of 1

 
Jump to: 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


 

 

Powered by phpBB © 2001, 2005 phpBB Group
Design by Freestyle XL / Flowers Online.