SoftTree Technologies SoftTree Technologies
Technical Support Forums
RegisterSearchFAQMemberlistUsergroupsLog in
Search and Replace within all scripts
Goto page 1, 2  Next
 
Reply to topic    SoftTree Technologies Forum Index » 24x7 Scheduler, Event Server, Automation Suite View previous topic
View next topic
Search and Replace within all scripts
Author Message
Jason Hoskins



Joined: 12 Mar 2004
Posts: 68

Post Search and Replace within all scripts Reply with quote
Is there a way to search and replace certain text in all JAL scripts in my job database? For example, I want to change all "24x7.com" to "24x7change.net" in all of my scripts.
Tue Jul 29, 2008 9:54 am View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 6717

Post Reply with quote
There is no built-in global search and replace function, but you can create a relatively simple script job to do that.

Here is an example for 24x7 Multi-platform Edition written in JavaScript. http://www.softtreetech.com/support/phpBB2/viewtopic.php?t=22420&highlight=global+replace

You can do something similar in JAL. Here is a slightly modified example from JobList topic from the 24x7 on-line help file

Code:
// declare script variables
Dim( job_list, string )
Dim( no_more, boolean )
Dim( job_id, string )
Dim( job_script, string )

// build job list
JobList( "", job_list )

// parse the list
isEqual( job_list, "", no_more )

LoopUntil( no_more, END_LOOP )
   // get next job ID
   GetToken(",", job_list, job_id )
   // get job script
   JobDescribe( job_id, "SCRIPT", job_script )
                // replace all occurrences of 24x7.com with 24x7change.net using custom ReplaceAll
                // statement (see example in the Example Jobs.dat)
   ReplaceAll( job_script, "24x7.com", "24x7change.net ")
   // modify job script
   JobModify( job_id, "SCRIPT", job_script )

   isEqual( job_list, "", no_more )
END_LOOP:


Similar thing can be also done in a VBScript job
Tue Jul 29, 2008 10:34 am View user's profile Send private message
Jason Hoskins



Joined: 12 Mar 2004
Posts: 68

Post Script truncated Reply with quote
My scripts are being truncated. Is there a limit on the string type?

Thanks.
Fri Aug 15, 2008 3:44 pm View user's profile Send private message
Jason Hoskins



Joined: 12 Mar 2004
Posts: 68

Post New Job numbers Reply with quote
Also, it is assigning new job IDs. Is there any way to avoind both of these issues without modifying manually?
Fri Aug 15, 2008 4:04 pm View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 6717

Post Reply with quote
Inline scripts have 32 KB size limit, offline scripts referenced via @SCRIPT macro have no size limit for number of characters but may not have more than 32765 lines of code (I cannot imagine a job of this size). It is also possible to move common parts of job scripts into user-defined script library.
Fri Aug 15, 2008 5:35 pm View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 6717

Post Reply with quote
I'm not sure I understand what you meant by "it is assigning new job IDs" Please provide steps to reproduce this issue.
Fri Aug 15, 2008 5:36 pm View user's profile Send private message
Jason Hoskins



Joined: 12 Mar 2004
Posts: 68

Post Script Size Reply with quote
Is it possible to determine the script size so I can exclude modification if > 32 KB? I would log this instead to be a manual update.
Mon Aug 18, 2008 8:19 am View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 6717

Post Reply with quote
You can use File/Export menu to save the script into a file and then check the resulting file size.
Mon Aug 18, 2008 10:53 am View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 6717

Post Reply with quote
I meant the menu in the script editor.
Mon Aug 18, 2008 10:54 am View user's profile Send private message
Jason Hoskins



Joined: 12 Mar 2004
Posts: 68

Post Reply with quote
I followed it through and the job_script variable is correct for this statement. It contains all 79 lines. I run

JobModify( job_id, "SCRIPT", job_script )

and the script is truncated to 12 lines every time.

Thanks for the help!
Mon Aug 18, 2008 1:07 pm View user's profile Send private message
Jason Hoskins



Joined: 12 Mar 2004
Posts: 68

Post Reply with quote
21 lines actually every time. Is there a limitation on JobModify?
Mon Aug 18, 2008 1:13 pm View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 6717

Post Reply with quote
Sorry, I misunderstood your original post. I assumed you were referring to regular job scripts, not dynamically created scripts.

Are you sure the truncation occurs during JobModify operation and not in ReplaceAll?
Mon Aug 18, 2008 1:29 pm View user's profile Send private message
Jason Hoskins



Joined: 12 Mar 2004
Posts: 68

Post Reply with quote
Yes. I followed it all the way through and the variable is correct.
Mon Aug 18, 2008 1:34 pm View user's profile Send private message
Jason Hoskins



Joined: 12 Mar 2004
Posts: 68

Post Reply with quote
Here is my script. Line 108 has the problem:

// declare script variables
Dim( job_list, string )
Dim( no_more, boolean )
Dim( job_id, string )
Dim( job_script, string )
Dim( job_script_msg, string )
Dim( job_script_msg_ori, string )
Dim( job_script_ori, string )
Dim job_script_msg_code string
dim job_script_msg_code_ori string
Dim( script_changes, boolean)
Dim( msg_changes, boolean)
Dim( i number)
Dim (result, string)
Dim (file_number, number)
Dim Comment string
Dim note_changes boolean
dim job_name string


Set (i, 0)

// build job list
JobList( "", job_list )
Concat( job_list, ",*done*", job_list)

//Remove this job from the list
ReplaceAll( job_list, ",1043", "", job_list)

FileOpen( "d:\\temp\\JobUpdate.txt", "LineMode", "Write", "FALSE", file_number )
FileWrite (file_number, "Job IDs for modified jobs.")
FileClose(file_number)

//Testing
Set (job_list, "1007,*done*")

// parse the list
isEqual( job_list, "", no_more )

LoopUntil( no_more, END_LOOP )
Set ( job_script_ori, "")
Set ( job_script, "")
Set ( job_script_msg_ori, "")
Set ( job_script_ori, "")
Set ( job_script_msg_code, "")
Set ( job_script_msg_code_ori, "")

// get next job ID
GetToken(",", job_list, job_id )
JobDescribe( job_id, "NAME", job_name)
// get job script
JobDescribe( job_id, "SCRIPT", job_script )

Set (job_script_ori, job_script)

//Script 24x7TOWER Update
ReplaceAll( job_script, "24x7tower.com", "24x7sc.net ", job_script)

//Script 24x7SC Update
ReplaceAll( job_script, "24x7sc.com", "24x7sc.net ", job_script)
isEqual (job_script_ori, job_script, script_changes)


//***********************************
//Script 24x7SC Update - TESTING
// ReplaceAll( job_script, "24x7sc.net", "24x7sc.com ", job_script)
// isEqual (job_script_ori, job_script, script_changes)
//***********************************


//Get Recipient List
JobDescribe( job_id, "MSG_RECIPIENT", job_script_msg )
Set (job_script_msg_ori, job_script_msg)

//Email 24x7TOWER Recipients Update
ReplaceAll( job_script_msg, "24x7tower.com", "24x7sc.net ", job_script_msg)

//Email 24x7SC Recipients Update
ReplaceAll( job_script_msg, "24x7sc.com", "24x7sc.net ", job_script_msg)
isEqual (job_script_msg_ori, job_script_msg, msg_changes)


//***********************************
//Script 24x7SC Update - TESTING
// ReplaceAll( job_script_msg, "24x7sc.com", "24x7sc.net ", job_script_msg)
// isEqual (job_script_msg_ori, job_script_msg, msg_changes)
//***********************************




//Get Script Notification List
JobDescribe( job_id, "MSG_SCRIPT_CODE", job_script_msg_code )
Set (job_script_msg_code_ori, job_script_msg_code)

//Email 24x7TOWER Recipients Update
ReplaceAll( job_script_msg_code, "24x7tower.com", "24x7sc.net ", job_script_msg_code)

//Email 24x7SC Recipients Update
ReplaceAll( job_script_msg_code, "24x7sc.com", "24x7sc.net ", job_script_msg_code)
isEqual (job_script_msg_code_ori, job_script_msg_code, note_changes)




If (script_changes, Update_Recip, Update_Script)

Update_Script:
JobModify( job_id, "SCRIPT", job_script )
FileOpen( "d:\\temp\\JobUpdate.txt", "LineMode", "Write", "TRUE", file_number )
ConcatEx ("SCRIPT Update: \"", job_name, "\" - ", job_id, comment)
FileWrite (file_number, comment)
FileClose(file_number)
Add( i, 1, i )

Update_Recip:
If (msg_changes, Update_Script_Note, process_Recip)

process_Recip:
JobModify( job_id, "MSG_RECIPIENT", job_script_msg )
FileOpen( "d:\\temp\\JobUpdate.txt", "LineMode", "Write", "TRUE", file_number )
ConcatEx ("MSG_RECIPIENT Update: \"", job_name, "\" - ", job_id, comment)
FileWrite (file_number, comment)
FileClose(file_number)
Add( i, 1, i )


Update_Script_Note:
If (note_changes, Next, process_Script_Note)

process_Script_Note:
// JobModify( job_id, "MSG_SCRIPT_CODE", job_script_msg_code )
FileOpen( "d:\\temp\\JobUpdate.txt", "LineMode", "Write", "TRUE", file_number )
ConcatEx ("MSG_SCRIPT_CODE Update: \"", job_name, "\" - ", job_id, comment)
FileWrite (file_number, comment)
FileClose(file_number)
Add( i, 1, i )


Next:

isEqual( job_list, "*done*", no_more )

END_LOOP:
string (i,result)
concatex ( result , " jobs updated.", result)
FileOpen( "d:\\temp\\JobUpdate.txt", "LineMode", "Write", "TRUE", file_number )
FileWrite (file_number, result)
FileClose(file_number)
// messagebox(result)
Mon Aug 18, 2008 1:38 pm View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 6717

Post Reply with quote
Please post one of your sample jobs so we can take your script and reproduce this issue. If necessary, before posting replace sensitive information with some dummy data.
Mon Aug 18, 2008 1:40 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
Goto page 1, 2  Next
Page 1 of 2

 
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.