Junos Automation (Scripting)
Junos Automation (Scripting)

array to string conversion

[ Edited ]
02.01.12   |  
‎02-01-2012 03:07 AM

Hello All,

 

What I was wondering is how I can convert an array into a string.

The reason for this is to search for a pattern using a regex into the string (consisted of the array elements).

The array is initialized like this :

var $cmd_syslog = <command> "show log messages | match SNMP_TRAP_LINK_DOWN" ;
var $file_content = jcs:execute( $connection, $cmd_syslog ) ;
var $lines = jcs:break-lines( $file_content )[ string-length()>0 ] ;

 

Many Thanks.

2 REPLIES
Highlighted
Junos Automation (Scripting)

Re: array to string conversion

02.02.12   |  
‎02-02-2012 09:06 AM

Take a look at the str:concat() function, discussed in the SLAX 1.0 Reference Guide on pages 257-258.

 

This Week: Junos Automation Reference for SLAX 1.0 - Juniper Networks

 

BTW, instead of breaking and then recombining the string input minus its newlines perhaps you could just translate() the newlines away so it is just one giant string to start with? Also, pipes are not supported within scripts. It might work but it might not.

Junos Automation (Scripting)

Re: array to string conversion

[ Edited ]
02.02.12   |  
‎02-02-2012 12:14 PM

Thank you ccall.

But how you can concat() in a for-each loop (through all the lines of the syslog).

 

Given that I have a for-each() loop and

in that loop, there is an if() statement, and if that is true(),

I would like to concat the syslog line and to a string.

 

How can I do that ?