Calling bash command in perl script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Calling bash command in perl script
# 1  
Old 12-03-2010
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:
PHP Code:
/usr/openv/netbackup/bin/admincmd/bperror -backstat --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:

PHP Code:
]#!/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 -"Client $client : $hostname Code $codemymail\@company.com`;

                }
}
close(FILE); 
Can someone tell me how to directly put those bash line in perl?
# 2  
Old 12-03-2010
Declare use Getopt::EvaP at the begining.

Code:
use Getopt::EvaP;

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

R0H0N
# 3  
Old 12-04-2010
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

PHP Code:
`/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:

PHP Code:
/usr/openv/netbackup/bin/admincmd/bperror -backstat --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;
PHP Code:

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?
# 4  
Old 12-07-2010
not getting an answer yet
# 5  
Old 12-08-2010
Sorry..!! I didn't understand your question.

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

PHP Code:
#!/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 -"Client $client : $hostname Code $codemymail@company.com`;

                }
}
close(FILE); 
Use "\"(escape character) wherever required in "$cmd" initialization.
R0H0N
# 6  
Old 12-08-2010
Calling bash command in perl script

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.

# 7  
Old 12-08-2010
Hi R0H0N,

Lets just focus on this:
Code:
#!/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.
Code:
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

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Calling bash script from CGI

Hi, I am having two individual scripts Script 1): CGI script - is a simple script which trigger bash script Script 2): Bash script - is a script which execute which collects file system utilization information from all the Unix servers If I am executing CGI script manually from command... (2 Replies)
Discussion started by: Naveen.6025
2 Replies

2. Shell Programming and Scripting

Calling msys shell from bash script

Hi all, I am struck at a very tricky problem. Writing a bash script that calls msys.bat which inherently launches sh.exe. Now from my bash script, I call msys.bat and it creates a shell within. The problem is: I cannot pass any commands to this new shell from my bash script. I need to be able to... (5 Replies)
Discussion started by: sweetu1995
5 Replies

3. Shell Programming and Scripting

Password check in bash script calling on expect

password check in bash script calling on expect Background: I have to copy a file from one server, to over 100 servers in a test environment. once the file is copied, it requires to have the permissions on the file changed/verified. These are all linux servers. most of them have the same... (1 Reply)
Discussion started by: 2legit2quit
1 Replies

4. Shell Programming and Scripting

Calling function from another bash script

I would like to call functions from another bash script. How can I do it? Some code More code (11 Replies)
Discussion started by: kristinu
11 Replies

5. Shell Programming and Scripting

calling a perl script with arguments from a parent perl script

I am trying to run a perl script which needs input arguments from a parent perl script, but doesn't seem to work. Appreciate your help in this regard. From parent.pl $input1=123; $input2=abc; I tried calling it with system("/usr/bin/perl child.pl $input1 $input2"); and `perl... (1 Reply)
Discussion started by: grajp002
1 Replies

6. Shell Programming and Scripting

How to call a bash command from within a perl script?

In a bash script, one can call a perl command in the following manner, where "myperlcommand" is a perl command. perl -e 'myperlcommand(arguments)' perl -e 'print("UUUU"x4)' Now, how can one call a bash command from within a perl script? (Suppose that mybashcommand is a bash... (1 Reply)
Discussion started by: LessNux
1 Replies

7. Shell Programming and Scripting

Calling a Perl script in a Bash script -Odd Situation

I am creating a startup script for an application. This application's startup script is in bash. It will also need to call a perl script (which I will not be able to modify) for the application environment prior to calling the application. The problem is that this perl script creates a new shell... (5 Replies)
Discussion started by: leepet01
5 Replies

8. Red Hat

Calling BASH script from JAVA

Hi, I am trying to call a bash script from a java file. Code to call bash script will look like: Runtime runtime = Runtime.getRuntime(); Process process = runtime.exec("mybashfile.sh"); It is succesfully calling the bash file. I am using simple rm commands in the script to remove... (0 Replies)
Discussion started by: lakshman.forums
0 Replies

9. Shell Programming and Scripting

Quick question: calling c-shell script from bash

Hello, I have a quick reference question: I have a very long, but fairly straigtforward script written in c-shell. I was wondering if it is possible to call this script from bash (for ex. having a function in bash script which calls the c-shell script when necessary), and if so, are there any... (1 Reply)
Discussion started by: lapiduslost
1 Replies

10. Shell Programming and Scripting

Calling 3 perl script from one

hi all, I have 3 perl scripts a.pl,b.pl and c.pl each of these work when i pass a date for eg: perl c.pl 2010-05-27 now i want to write a perl script that would call the 3 scripts and make it run all the 3 scripts (a.pl,b.pl,c.pl) parallelly rather than 1 after the other....... pls... (2 Replies)
Discussion started by: siva_nagarajan
2 Replies
Login or Register to Ask a Question