09-22-2010 01:39 PM
Does anyone have experience writing to files from an op script? I've tried using jcs:execute functions with rpc commands (as shown below) without success. The script completes successfully and even outputs what I would expect in the results-* variables, but when I try to view the files, they are not there.
var $connection = jcs
pen();
var $rpc-rsi = <rpc> {
<command> {
expr "request support information | save /var/tmp/rsi.txt"; } }
var $results-rsi = jcs:execute($connection, $rpc-rsi);
var $rpc-archive = <rpc> {
<command> {
expr "file archive source /var/tmp/rsi.txt compress destination /var/tmp/rsi.tgz"; } }
var $results-archive = jcs:execute($connection, $rpc-archive);
09-22-2010 02:07 PM
You can use the <exsl:document> or <redirect:write> extensions to write to a local file.
You can find information on <exsl:document> here: http://www.exslt.org/exsl/elements/document/index.
and
You can find information on <redirect:write> here:http://xml.apache.org/xalan-j/extensionslib.html
Hope this helps!
-- Jeremy
10-06-2010 12:07 PM
Thanks for the info. I was able to direct the output from a command into a file using the file-put command:
var $rpc-rsi = <command> { expr "request support information"; }
var $rsi-output = jcs:execute($connection, $rpc-rsi);
var $rpc-rsi-write = {
<file-put> {
<filename> "/var/tmp/baseline-info/rsi.txt";
<encoding> "ascii";
<delete-if-exist>;
<file-contents> $rsi-output;
}
}
However, I am having problems trying to compress this file (and others) before copying to an FTP server. Coping to an FTP server is pretty straightforward using the file-copy command, but there does not seem to be an option to compress using the file-copy command and I don't see any archive type command. I tried configuring the following:
var $rpc-archive = <command> { expr "file archive source /var/tmp/baseline-info compress destination ftp://<user>:<pass>@<ip>/<dir>/baseline-info.tgz"; }
var $archive-call = jcs:execute($connection, $rpc-archive);
But when I enabled traceoptions on the op script I saw that this operation is not allowed:
<rpc-reply xmlns:junos="http://xml.juniper.net/junos/10.1R3/junos" xmlns="">
<output>
/usr/bin/tar: Removing leading `/' from member names
</output>
<xnm:error xmlns="http://xml.juniper.net/xnm/1.1/xnm" xmlns:xnm="http://xml.juniper.net/xnm/1.1/xnm">
<message>
Operation allowed only from CLI
</message>
</xnm:error>
</rpc-reply>
Does anyone know of an archive type command for an op script or are there plans to support a 'file-archive' operational command?