Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 12-01-2017, 11:24 PM
jack_george jack_george is offline
Registered User
 
Join Date: Nov 2017
Posts: 12
Wink replace string in router config. using python

Hello
i try to run python script in securecrt for juniper routers such i show configuration on it then make change/replace for strings in it, i want to take output of show configuration then put it to list then make changes then change it to string then apply it.

example as below:

Code:
@router> ...tch ARI |display set

#set policy-options policy-statement STM64-L1 term ARI from route-filter 1.1.1.1/32 exact 
#set policy-options policy-statement STM64-L1 term ARI then accept
#set policy-options policy-statement STM64-L1 term rej then reject
in it i want to replace string STM64-L1 with 10G-L100 then apply configuration to router again as string

my code as below:

Code:
crt.Screen.Synchronous = True
JGR= crt.Dialog.Prompt("enter term name that will applied: ")    
rep= crt.Dialog.Prompt("enter term name that will removed ")     
pol= crt.Dialog.Prompt("enter policy that will remove term from it ")    
npt= crt.Dialog.Prompt("enter policy that will add term to it ")    
crt.Screen.Send("show configuration | display set | match " +JGR+ "\n")
crt.Screen.WaitForString("/n")
x=crt.Screen.ReadString("exact")
x.split(",")
term_name=x
term_name=list()
for word in term_name:
    h=term_name.index(pol)
    term_name.pop(h)
    term_name.insert(h,npt)
yyy= ' '.join(term_name)
crt.Screen.Send("edit private "+ "\n")
crt.Screen.WaitForString("router#")
crt.Screen.Send(yyy+ "\n")
crt.Screen.WaitForString("router#")
crt.Screen.Send("show | compare " + "\n")
crt.Screen.Synchronous = False
main()
but i face problem that script run without errors but no configuration applied like that value of yyy is just space ?

Thanks

Last edited by jdev; 12-05-2017 at 12:37 PM.
Reply With Quote
 

Tags
python


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 01:41 AM.