View Single Post
  #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