Reply

Perl - Create a new File in Job to fill with Data

MI_Informatic
Techie
Posts: 2
5414     0

Hello Guys,

 

i started to create a Perl Script in NetMRI, i want to send commands to a Switch and put the response in a variable. After then i want to create a new File in Job and fill the File with the response-variable. Now i have the Problem to create a new File in Job...

 

If the Job finished i want to see the File in the "Job Details Viewer" in the Files. I have tried several Opportunities which i have read in Forums... without success..

 

Which Path should i use if i create a File in a job?

 

Example from my idea:

 

################################

use strict;

use warnings;

use NetMRI_Easy 0.6;

 

my $RunCfg = "";

 

$easy->send_command("show run\r");

 

*NOW Create File in Job an print $RunCfg*

##################################

 

For Example (Only one from many ways i have tried...):

 

open(my $fh, ">", "$file")

or die "Could not open file '$file' $!";

 print {$fh} $RunCfg . "\n";

close FILE;

 

Does not work (No Errors but the File does not exist in Job Viewer after run the Script)

 

I hope anyone can help me before i start to cry Smiley Very Happy

 

 

Re: Perl - Create a new File in Job to fill with Data

Expert
Posts: 185
5414     0

 

All you need to do is just a 'print' and it will show in the Status Log file of the Job Details Viewer.

 

Change:  

print {$fh} $RunCfg . "\n";

 

To:

print $RunCfg . "\n";

 

 

Below is sample code to print components:

#!/usr/bin/perl -w
# BEGIN-SCRIPT-BLOCK
# Script-Filter: $Vendor == "Cisco" and $type in ["Router","Switch-Router","Switch"] and $sysdescr like /IOS|NX-OS/
# 
# Script-Timeout: 600
# Script-Login:
# true
#
# Script-Variables:
# END-SCRIPT-BLOCK

use strict;
use warnings;
use NetMRI_Easy;

my $easy = new NetMRI_Easy;

my @physicals = $easy->broker->device_physical->index({
	DeviceID => $easy->device_id,
});

foreach my $physical (@physicals)
{
	print $physical->DevicePhysicalID,"\t",$physical->PhysicalDescr,"\n";
}

1;

-Lon.

Re: Perl - Create a new File in Job to fill with Data

MI_Informatic
Techie
Posts: 2
5414     0

Thanks for your Answer Lon.

 

The Reason why i want to create a new File is to take Results from my Scripts and querys for further tasks in NetMRI and other Tools.

 

Youre right, with only print i can see the results from my commands but that's not enough and i must to copy the Status log manually in a editor..

 

Is there no way in NetMRI to create a new File in a Job ? Write variables in this log and download the File in the Job Details Viewer?

Highlighted

Re: Perl - Create a new File in Job to fill with Data

Expert
Posts: 185
5414     0

 

It sounds to me that if you are wanting to export data to other tools then you should be doing the scripting in the sandbox or on another server and use the NetMRI API.

 

If you just need to trigger an issue within NetMRI and have another NetMRI job remediate the issue, I'd use a CCS script to create the issue.

 

Maybe I don't have the big picture here of what you are trying to accomplish.

 

Lon.

Showing results for 
Search instead for 
Do you mean 

Recommended for You