Author |
Message |
barefootguru
Joined: 10 Aug 2007 Posts: 195
|
|
Global find & replace in job database |
|
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.
|
|
// 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 |
|
|
SysOp
Site Admin
Joined: 26 Nov 2006 Posts: 7849
|
|
|
|
Very nice. Thank you!
|
|
Thu Jul 10, 2008 5:35 pm |
|
|
seanc217
Joined: 23 May 2007 Posts: 272
|
|
|
|
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 |
|
|
SysOp
Site Admin
Joined: 26 Nov 2006 Posts: 7849
|
|
|
|
AGENT
|
|
Mon Nov 10, 2008 7:07 pm |
|
|
barefootguru
Joined: 10 Aug 2007 Posts: 195
|
|
|
|
See also the 'Job Properties in JDL Format' section in the 24x7 JavaScript Reference
|
|
Mon Nov 10, 2008 7:55 pm |
|
|
seanc217
Joined: 23 May 2007 Posts: 272
|
|
|
|
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 |
|
|
SysOp
Site Admin
Joined: 26 Nov 2006 Posts: 7849
|
|
|
|
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 |
|
|
seanc217
Joined: 23 May 2007 Posts: 272
|
|
|
|
I did uncheck detached and I receive the same error.
|
|
Tue Nov 11, 2008 12:13 pm |
|
|
seanc217
Joined: 23 May 2007 Posts: 272
|
|
|
|
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 |
|
|
SysOp
Site Admin
Joined: 26 Nov 2006 Posts: 7849
|
|
|
|
Oh good. Thanks for the status update.
|
|
Tue Nov 11, 2008 12:25 pm |
|
|
|