Calling bash command in perl script

Hi,

I have tried several times but failed, I need to call this script from the perl script. This one line script will be sent to /var/tmp/error

Bash command:

/usr/openv/netbackup/bin/admincmd/bperror -backstat -l -hoursago 12 |awk '{ print $19, $12, $14, $16}'|grep -vi default|sort > /var/tmp/error.out

For now i have to create another bash script and call that script from this perl script. If i embedded directly above line in the perl it will failed. This is the perl script:

]#!/usr/bin/perl
#Calling the bash script
`/script/bperror14 > /var/tmp/errorout`;
#

open FILE, "/var/tmp/errorout" or die $!;
chomp($hostname=`uname -n`);
chomp($date=`date`);
$count=0;
#
while (<FILE>)
{
        ($code,$client,$policy,$sched) = split(/ /,$_);
                {
mailx -s "Client $client : $hostname Code $code" mymail\@company.com`;

                }
}
close(FILE);

Can someone tell me how to directly put those bash line in perl?

Declare use Getopt::EvaP at the begining.

use Getopt::EvaP;

`/script/bperror14 > /var/tmp/errorout`;

Hi, sorry im not getting what you try to point to me:

This is currently i use, in this case i have to call another script

`/script/bperror14 > /var/tmp/errorout`;

What i need now is, to run below script (it is /script/bperror14 )directly from the perl script it self. The bperror14 script is as below:

                       
/usr/openv/netbackup/bin/admincmd/bperror -backstat -l -hoursago 12 |awk '{ print $19, $12, $14, $16}'|grep -vi default|sort > /var/tmp/error.out  

BTW, i got below message when i put use Getopt::EvaP;

Can't locate Getopt/EvaP.pm in @INC (@INC contains: /usr/perl5/5.6.1/lib/sun4-solaris-64int /usr/perl5/5.6.1/lib /usr/perl5/site_perl/5.6.1/sun4-solaris-64int /usr/perl5/site_perl/5.6.1 /usr/perl5/site_perl /usr/perl5/vendor_perl/5.6.1/sun4-solaris-64int /usr/perl5/vendor_perl/5.6.1 /usr/perl5/vendor_perl .) at ./filter_script line 6.
BEGIN failed--compilation aborted at ./filter_script line 6.

---------- Post updated 12-04-10 at 12:10 PM ---------- Previous update was 12-03-10 at 01:04 PM ----------

still failed, anyone?

not getting an answer yet

Sorry..!! I didn't understand your question.

Now here is one simple solution for that. You can use system command to solve this problem.

#!/usr/bin/perl
#Calling the bash script
my $cmd = "\/usr\/openv\/netbackup\/bin\/admincmd\/bperror -backstat -l -hoursago 12 |awk '{ print $19, $12, $14, $16}'|grep -vi default|sort > \/var\/tmp\/error.out";
system("$cmd");
#`/script/bperror14 > /var/tmp/errorout`;
#

open FILE, "/var/tmp/errorout" or die $!;
chomp($hostname=`uname -n`);
chomp($date=`date`);
$count=0;
#
while (<FILE>)
{
        ($code,$client,$policy,$sched) = split(/ /,$_);
                {
mailx -s "Client $client : $hostname Code $code" mymail@company.com`;

                }
}
close(FILE);  

Use "\"(escape character) wherever required in "$cmd" initialization.

yes , u can use the system command to include your script in perl code.
otherewise try to grep EvaP.pm and if found .
Add the path to the @inc using push command .

Then again use this method :

use Getopt::EvaP;

hope this will help U.

Hi R0H0N,

Lets just focus on this:

#!/usr/bin/perl
#Calling the bash script
my $cmd = "\/usr\/openv\/netbackup\/bin\/admincmd\/bperror -backstat -l -hoursago 12 |awk '{ print $19, $12, $14, $16}'|grep -vi default|sort > \/var\/tmp\/error.out";
system("$cmd");
#`/script/bperror14 > /var/tmp/errorout`;
#

This code also doesn't produce any files in /var/tmp/errorout, the script seems stop at awk statement.

I tried to put backslash \ in front of $19, $12, $14, $16 but at the end it does not print column 19.

my $cmd = "\/usr\/openv\/netbackup\/bin\/admincmd\/bperror -backstat -l -hoursago 12 |awk '{ print \$19, \$12, \$14, \$16}'|grep -vi default|sort > \/var\/tmp\/error.out";

Getopt::EvaP is not installed

To findout what exactly happening, print command before execution. I mean

my $cmd = "\/usr\/openv\/netbackup\/bin\/admincmd\/bperror -backstat -l -hoursago 12 |awk '{ print \$19, \$12, \$14, \$16}'|grep -vi default|sort > \/var\/tmp\/error.out";
system("echo $cmd");

This will ensure you what exactly it is being executed??

nothing was produce in /var/tmp/error.out, its a blank file.

was the command echoed correctly? if yes then there may be a problem in your logic.

it was work perfectly outside perl if i run directly in bash

try

my $cmd = "sh \/usr\/openv\/netbackup\/bin\/admincmd\/bperror -backstat -l -hoursago 12 |awk '{ print \$19, \$12, \$14, \$16}'|grep -vi default|sort > \/var\/tmp\/error.out";

same, no output were produce