- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
Need to manipulate variables within a CCS script -- How do I do this?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
08-19-2014 11:49 AM
I was attempting to write a script that would pull the IP address of a device from the configuration, and manipulate the individual octet values and use the manipulated values to modify the configuration. After speaking to Sif (thanks Sif!), he mentioned that "expr" is how this is done. It took a bit of playing around, but I was able to come up with a valid script as follows:
Script-Filter:
$Vendor eq "Cisco"
#########################################################################
Action:
Modify ACL to allow SSH
Action-Description:
Modify ACL to allow SSH
Action-Commands:
show running-config interface vlan345 | include ip address
Output-Triggers:
Create access-list
#########################################################################
Trigger:
Create access-list
Trigger-Description:
Configure ACL 5 and other parameters
Trigger-Variables:
$VLAN345 integer
$VLAN346 integer
$OCT3 integer
$OCT4NET integer
$OCT4FIRST integer
$OCT4SECOND integer
Trigger-Template:
ip address 10\.[[$VLAN345]]\.[[$OCT3]]\.[[$OCT4FIRST]] 255.255.255.240
Trigger-Commands:
expr: $VLAN346 = $VLAN345 - 16
expr: $OCT4NET = $OCT4FIRST - 1
expr: $OCT4SECOND = $OCT4FIRST + 1
conf t
line vty 0 4
no access-class 10 in vrf-also
exit
no access-list 10
access-list 10 permit 10.$VLAN345.$OCT3.$OCT4NET 0.0.0.15
access-list 10 permit 10.$VLAN346.$OCT3.$OCT4SECOND
line vty 0 4
access-class 10 in vrf-also
end
wr
#########################################################################
Thanks again for the help, Sif!
Unfortunately, you can't. I
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
09-02-2014 11:17 AM
Unfortunately, you can't. I've beaten my head against this a few times now... spent most of yesterday experimenting with this specifically to no avail.
With the exception of filters, variable type definitions are meaningless in commands and they are all treated as strings.
You will want to use Perl instead of CCS, if you need a number to behave as a number.
Daniel,
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
09-02-2014 07:04 PM
Daniel,
The script above works, let's setup a call next week, when I'm working in the home office.
You have to make sure you capture it as an integer and not a string. I helped Tim work this script out.
Thanks,
Sif
Twitter: https://twitter.com/sifbaksh
A call sounds good.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
09-03-2014 08:53 AM
A call sounds good.
Does the complexity of the math, or the position of the variable in the string make a difference?
Trigger-Variables:
$str /\d{4}/ number # i also tried '$str int'
Trigger-Commands:
EXPR: $second = (10000+$str)/64
EXPR: $third = (((10000+$str) %64) *4)+1
I then tried to use them in an action with-
ip address 10.$second.$third.252 255.255.255.0
but it would fail with invalid input because the result is never calculated.
*** Invalid input detected ***
Switch(config-if)#ip address 10.(10000+4101)/64..253 255.255.255.0
^
% Invalid input detected at '^' marker.
Try the following:
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
09-03-2014 11:50 AM
Try the following:
For
EXPR: $second = (10000+$str)/64
Do:
EXPR: $second = 10000+$str
EXPR: $second = $second/64
I do belive you have to break each one out:
EXPR: $third = (((10000+$str) %64) *4)+1
EXPR: $third = 10000+$str
EXPR: $third = $third%64
EXPR: $third = $third*4
EXPR: $third = $third+1
Let me know i that works for you
Twitter: https://twitter.com/sifbaksh
Still getting the same
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
09-03-2014 12:47 PM
Still getting the same results - tried a couple variations
![]() |
||
![]() |
||
![]() |
||
![]() |
||
![]() |
|
![]() |
|
||||
![]() |
|
Found something when I looked
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
09-04-2014 10:44 PM
Found something when I looked at the man pages for expr on my linux box, you need spaces beween the symblos
|
|||||
![]() |
|||||
![]() |
|||||
![]() |
|
So you just need to do the following:
EXPR: $base = $test + 10000 - notice the space between $test and + and then between + 10000
Let me know if it works for you, I'm on version 6.8.6
Sif
Twitter: https://twitter.com/sifbaksh
I also checked you command
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
09-05-2014 06:35 AM
I also checked you command and it worked as well with spaces
![]() |
|||||
|
|||||
![]() |
|||||
![]() |
|||||
![]() |
|||||
![]() |
|
||||
![]() |
|
Twitter: https://twitter.com/sifbaksh
Thanks Sif! That worked.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
09-05-2014 07:28 AM
Thanks Sif! That worked.
In this specific case, i ended up writing the script for Perl because I needed it this week, but this will be very handy for future scripts.
Re: Need to manipulate variables within a CCS script -- How do I do this?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
04-10-2019 05:05 AM
Is this code still working?
Re: Need to manipulate variables within a CCS script -- How do I do this?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
04-10-2019 07:33 AM
Why don't you start by creating a new posting linking to this and an example of what you are trying to do
Or the script, we will help
Twitter: https://twitter.com/sifbaksh