Junos Automation (Scripting)
Reply
Contributor
onedreamcloser
Posts: 16
Registered: ‎05-13-2011
0

array to string conversion

[ Edited ]

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.

Recognized Expert
ccall
Posts: 230
Registered: ‎06-18-2008
0

Re: array to string conversion

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.

Contributor
onedreamcloser
Posts: 16
Registered: ‎05-13-2011
0

Re: array to string conversion

[ Edited ]

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 ?

Copyright© 1999-2013 Juniper Networks, Inc. All rights reserved.