Automation

last person joined: 3 days ago 

Ask questions and share experiences about Apstra, Paragon, and all things network automation.
  • 1.  Read text file - file show /var/tmp/file.name?

    Posted 03-19-2013 18:10

    Created this function, but it's returning an empty string.

     

    Running through juice the file is transfered, and read, but doesn't make it into the results.

     

    <func:function name="common:read-file-contents">
    {
            param $jre;
            param $ftp-server;
            param $file-name;

            var $remote-file = "ftp://user:pw@" _ $ftp-server _ "/" _ $file-name;
            var $local-file = "/var/tmp/" _ $file-name;
            var $rpc-copy = <file-copy> {
                                            <source> $remote-file;
                                            <destination> $local-file;
                                    }
            var $rslt-copy = jcs:execute($jre, $rpc-copy);

            var $rpc-show = <file-show>{
                                            <filename>$local-file;
                                    }
            var $rslt-show = jcs:execute($jre, $rpc-show);

            <func:result select="string($rslt-show//file-content)">;
    }

     

     

    The response is:

     

    <rpc-reply xmlns:junos="http://xml.juniper.net/junos/11.2R2/junos">
        <file-content filename="/var/tmp/current.version" junos:seconds="1363741717" filesize="9" encoding="text">
            12.1R4.7
        </file-content>
        <cli>
            <banner></banner>
        </cli>
    </rpc-reply>

     

    Any ideas?



  • 2.  RE: Read text file - file show /var/tmp/file.name?

    Posted 03-20-2013 03:26

    Have you tried using <file-get> in place of <file-show> ? 

     

    I use the <file-get> in my programs, but haven't used <file-show>.  I think there is a good explanation of the difference in the Day One Book: "Mastering Junos Automation Programming", section "File I/O: Reading".  URL here.

     

    HTH,

    -- Jeremy



  • 3.  RE: Read text file - file show /var/tmp/file.name?
    Best Answer

    Posted 03-20-2013 13:09
            var $rslt-show = jcs:execute($jre, $rpc-show);

            <func:result select="string($rslt-show//file-content)">;

     

     

    The context node of the <file-show> result will be <file-content>, so you don't want to include it in your location path:

     

            <func:result select="$rslt-show">;