Network Change & Configuration Management

Reply
Accepted Solution

Escape double quotes in Trigger-Template

benzaam
Techie
Posts: 4
4500     1

Hi!

 

i'm trying to figure out how to not take double quotes in a variable assigned during the Trigger-Template part of a script.

 

Basically, I have this:

 

# 1 ########################################################################
Action:
Check current config for SNMP location

 

Action-Description:
Check current config for SNMP location

 

Action-Filter:
$runscript ne "no"

 

Action-Commands:
show configuration | display set

 

Output-Triggers:
Find sav_snmp_location

 

# 1.4 #######################################################################
Trigger:
Find sav_snmp_location

Trigger-Description:
This trigger determines the SNMP location already configured

Trigger-Variables:
$sav_snmp_location String

 

Trigger-Template:
set snmp location [[$sav_snmp_location]] #that value here is something like -> "Boucle 1 : dummy"

 

Trigger-Filter:
$runscript ne "no"

 

Trigger-Commands: { $sav_snmp_location ne "" }
SET: $sav_snmp_location =~ s/[\",\\]//g
PRINT (Pfile.txt): Benjamin $sav_snmp_location
SET: $val_snmp_location = $sav_snmp_location

 

 

The script just stops on error:

Bareword found where operator expected at (eval 2532) line 1, near ""\\"Boucle" (Missing operator before Boucle?) Number found where operator expected at (eval 2532) line 1, near "Boucle 1" (Do you need to predeclare Boucle?) Backslash found where operator expected at (eval 2532) line 1, near ")\" (Missing operator before \?)

 

As you can see it's adding backslashes as well to the variable, which then messes everything up.

Can anyone help with this please?

 

Thanks,

Benjamin

Re: Escape double quotes in Trigger-Template

Expert
Posts: 50
4500     1

Hello Benjamin,

 

1. you can try to define your own regex:

$sav_snmp_location /<you regex here>/

 

2. I am not sure if "SET: $sav_snmp_location =~ s/[\",\\]//g" is valid in regards of the regex expression.

 

 

Greets

 

Markus

Re: Escape double quotes in Trigger-Template

Expert
Posts: 236
4500     1

One other suggestion is to use the built-in CCS regex test to get your pattern matches working correctly before trying them in a running script.

http://netmriip/netmri/ccs/tx/regex_test/index.tdf

Highlighted

Re: Escape double quotes in Trigger-Template

Adviser
Posts: 390
4500     1

This will also work Smiley Happy

 14:05:46   Action-Commands 
 14:05:46     SET: $x = "set snmp location "Boucle 1 : dummy"" 
 14:05:46     SET: $x =~ s/"// 
 14:05:46     SET: $x =~ s/"// 
 14:05:46     desc set snmp location Boucle 1 : dummy 

 

 

So you can use the following:

Action:

Execute Command Batch

 

Action-Commands:

#this SET command you can use as the data you collected via the trigger

SET: $x = "set snmp location \"Boucle 1 : dummy\""

This command will remove the " in front of B and the 2nd will remove the ending "

SET: $x =~ s/\"//

SET: $x =~ s/\"//

desc $x

 

$x will now have the data with out the quotes

 

to use in the script you can do the following

set snmp location \"{$x}\"

 


Follow me on LinkedIn: https://www.linkedin.com/in/sifbaksh
Twitter: https://twitter.com/sifbaksh
Showing results for 
Search instead for 
Do you mean 

Recommended for You