Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Capture output of command and save to text file 1

Status
Not open for further replies.

n3tw0rkadm1n1strat0r

IS-IT--Management
Aug 29, 2006
119
US
I am new to perl and have started this script going off of another one. I am trying to capture the output of a command and save it to a text file. Here is what I have so far:

Code:
#!C:\Perl\bin\perl.exe

open (IN, "omnidb -session -latest -detail|") ;
while (<IN>)
{
$data = $_ ;


 
Ok so I replaced all the scripts, and they've run for a couple days...but I am still getting the same results. Any ideas?
 
Duh! 33 posts ago, in a bizarre parallel universe:
n3tw0rkadm1n1strat0r said:
1) Job 1 finishes.
2) Job 2 is still running.
3) Script runs and grabs output from latest job after job 1
finishes.
4) Since Job 2 is still running, it grabs the output from
that and not job 1.
I Googled 'omnidb' to find out what it does.
Code:
omnidb -session -latest -detail
Of course you're getting the same bloody results. What do you think the -latest parameter does? Apart from report on the latest backups you've taken, that is? Like, you know, the ones being taken by Job 2, perhaps?

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
Whoops...yeah sorry I overlooked that. I thought -latest was the last job that finished, not the latest one thats still running...Well at least I learned how to capure output and send it in an email!
 
Ok so I figured out the right way to do this, and I thought I'd let you guys know...here is the completed script:

Code:
#!C:\Perl\bin\perl.exe
# Take output of Data Protector Session and send in an email
 
use warnings;
use strict;
use MIME::Lite;
use Getopt::Std;

my $file = "output_" . time() . ".html";

open (IN, "omnirpt -report session_objects -session %SESSIONID% -html|") or die "$!";
open(OUT, ">$file") or die "$!";
while (<IN>)
{
print OUT $_ ;
}

close(OUT);

my $SMTP_SERVER = 'mailserver';
my $DEFAULT_SENDER = 'sender@email.com';
my $DEFAULT_RECIPIENT = 'to@email.com';
 
MIME::Lite->send('smtp', $SMTP_SERVER, Timeout=>60);
 
my (%o, $msg);
 
# process options
 
getopts('hf:t:s:', \%o);
 
$o{f} ||= $DEFAULT_SENDER;
$o{t} ||= $DEFAULT_RECIPIENT;
$o{s} ||= 'DAILY APPLICATIONS MSL JOB COMPLETE';
 
# construct and send email
 
$msg = new MIME::Lite(
    From => $o{f},
    To   => $o{t},
    Subject => $o{s},
    Data => "Test",
    Type => "multipart/mixed",
);
 

$msg->attach(  'Type' => 'application/octet-stream',
               'Encoding' => 'base64',
               'Path' => "C:/Program Files/OmniBack/bin/$file",
               'Disposition' => 'attachment' );

$msg->send(  );

unlink($file);

One quick question...how would I show the contents of the html in the email and not as an attachemnt?
 
it's covered in the MIME::Lite documentation.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top