AnsweredAssumed Answered

SSH Operator post-execution code regex

Question asked by Gold12345 on Jan 17, 2014
Latest reply on Jan 22, 2014 by Gold12345

I'm capturing the output using an SSH operator from a Cisco "sh vlan brief" command.
I want to capture 2 things from a specific matching line, where the first 3 chars of the name equal a variable i already have. I then want to store the vlan id and whole vlan name in my dataset.

Here is a sample output from the cmd
    VLAN Name                             Status    Ports
    ---- -------------------------------- --------- -------------------------------
    1000 abc.id07.wan                     active    
    1001 abb.id00.wan                     active    
    1002 abd.id01.wan                     active    
    1003 abe.id01.internet                active    Gi1/2
    1004 abf.id01.public                  active    Gi1/3
    1005 abg.hosted.internet              active    

This bit of code is working to find the correct line and assigning the whole line into both dataset vars.
var vlan_array=Process.vlan_query_by_customer_name.SSHCommandsOutput[1].split("\n");

//initialise the dataset vars to ERROR.

// foreach (config_line in vlan_array) {
for (var i = 0; i < vlan_array.length; i++) {
  if( vlan_array[i].indexOf(Datasets["mydataset"].customer) > -1) {
below is stuff i have already tried, where the commands are not supported in PAM
  //replaceAll not supported in PAM
  //var my_vlan_id = vlan_array[i].replaceAll("^([0..9][0..9][0..9][0..9]).+$", "$1");
  // matches not supported in PAM
  //if(vlan_array[i].matches(tempcust)) {
  //pattern not supported in PAM
  //Matcher m = Pattern.compile("([0..9][0..9][0..9][0..9])\s(.+)\s+.+").matcher(vlan_array[i]);
  //if (m.find()) {
  //     Datasets["mydataset"];
  //     Datasets["mydataset"];
  // contains not supported in PAM
  //if(vlan_array[i].contains(Datasets["mydataset"].customer)) {
  // Datasets["mydataset"].vlan_name=vlan_array[i];

Below is the Perl code for what i'm trying to do
if ($myvar =~ /^(\d+)\s($customer_name\S+)\s/) {
 print "var1=$1 var2=$2\n";