Question: Use a Perl Script to Make a Call to a Bourne Shell Script?

Question: Use a Perl Script to Make a Call to a Bourne Shell Script?

Post by Aristotl » Fri, 14 Jun 2002 03:20:38



Hello,

I am trying to get a Perl script that I have to make a call to a Bourne
Shell script...'kick it off' so to speak...what is the command I would use
to do that?

Thanks for any pointers!

A.

 
 
 

Question: Use a Perl Script to Make a Call to a Bourne Shell Script?

Post by soliscree » Fri, 14 Jun 2002 03:36:07


Maybe too simple:

#!/usr/bin/perl
system("/path/to/bash/script");

Sorry if it's not what you have in mind ...


> Hello,

> I am trying to get a Perl script that I have to make a call to a Bourne
> Shell script...'kick it off' so to speak...what is the command I would use
> to do that?

> Thanks for any pointers!

> A.


 
 
 

Question: Use a Perl Script to Make a Call to a Bourne Shell Script?

Post by Bruce Barnet » Fri, 14 Jun 2002 09:29:44



> Maybe too simple:

> #!/usr/bin/perl
> system("/path/to/bash/script");

Nah. Too complex. :-)

  `/path/to/bash/script`;

I presonally prefer
  $results=`/path/to/bash/script 2>&1`;

--
Sending unsolicited commercial e-mail to this account incurs a fee of
$500 per message, and acknowledges the legality of this contract.

 
 
 

Question: Use a Perl Script to Make a Call to a Bourne Shell Script?

Post by Aristotl » Fri, 14 Jun 2002 23:29:32




> > Maybe too simple:

> > #!/usr/bin/perl
> > system("/path/to/bash/script");

> Nah. Too complex. :-)

>   `/path/to/bash/script`;

> I presonally prefer
>   $results=`/path/to/bash/script 2>&1`;

> --
> Sending unsolicited commercial e-mail to this account incurs a fee of
> $500 per message, and acknowledges the legality of this contract.

Thanks for the reply - that worked great, however, now it's executing so
fast that it's running my bourne shell script before it is completely
written.  How would I go about inserting a pause for 30 seconds in the perl
script?

TIA,

A.

 
 
 

Question: Use a Perl Script to Make a Call to a Bourne Shell Script?

Post by Ed L Cashi » Fri, 14 Jun 2002 23:31:45


...

Quote:> Thanks for the reply - that worked great, however, now it's executing so
> fast that it's running my bourne shell script before it is completely
> written.  How would I go about inserting a pause for 30 seconds in the perl
> script?

Can't you just do things sequentially instead of waiting an arbitrary
amount of time?  

--
--Ed L Cashin            |   PGP public key:

 
 
 

Question: Use a Perl Script to Make a Call to a Bourne Shell Script?

Post by Aristotl » Sat, 15 Jun 2002 00:09:37





> ...
> > Thanks for the reply - that worked great, however, now it's executing so
> > fast that it's running my bourne shell script before it is completely
> > written.  How would I go about inserting a pause for 30 seconds in the
perl
> > script?

> Can't you just do things sequentially instead of waiting an arbitrary
> amount of time?

> --
> --Ed L Cashin            |   PGP public key:


It takes longer for the Bourne Shell to be written to the file then it does
for the Perl script to step through the code and run the Bourne Shell,
causing the file to be malformed and execute with errors...Any ideas?

A.

 
 
 

Question: Use a Perl Script to Make a Call to a Bourne Shell Script?

Post by Ed L Cashi » Sat, 15 Jun 2002 00:23:38






> > ...
> > > Thanks for the reply - that worked great, however, now it's executing so
> > > fast that it's running my bourne shell script before it is completely
> > > written.  How would I go about inserting a pause for 30 seconds in the
> perl
> > > script?

> > Can't you just do things sequentially instead of waiting an arbitrary
> > amount of time?

> > --
> > --Ed L Cashin            |   PGP public key:

> It takes longer for the Bourne Shell to be written to the file then it does
> for the Perl script to step through the code and run the Bourne Shell,
> causing the file to be malformed and execute with errors...Any ideas?

I must not understand what you mean.  Usually you don't write the
Bourne shell script to a file on the fly, but here's an example of
doing just that sequentially from a perl script:

  #! /usr/bin/perl -w

  use strict;

  &go;

  sub go {
      my $shfile = "/tmp/test-bourne.sh";

      open SHFILE, "> $shfile" or die "Error: could not open $shfile";

      print SHFILE "#! /bin/sh\n"
        . "echo 'hi there!!!'\n";
      close SHFILE;
      chmod 0755, $shfile;

      system $shfile;
  }

... and it works just like you'd expect:


  hi there!!!

--
--Ed L Cashin            |   PGP public key:

 
 
 

Question: Use a Perl Script to Make a Call to a Bourne Shell Script?

Post by Randal L. Schwar » Sat, 15 Jun 2002 02:48:09



>> #!/usr/bin/perl
>> system("/path/to/bash/script");

Bruce> Nah. Too complex. :-)

Bruce>   `/path/to/bash/script`;

That's working hard when it doesn't need.  Don't use backquotes
in a void context.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095

Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

 
 
 

Question: Use a Perl Script to Make a Call to a Bourne Shell Script?

Post by Barry Margoli » Sat, 15 Jun 2002 06:21:03





>> Maybe too simple:

>> #!/usr/bin/perl
>> system("/path/to/bash/script");

>Nah. Too complex. :-)

>  `/path/to/bash/script`;

Yuck.  Backticks should not be used unless you're saving the output
somewhere, as in your second suggestion:

Quote:>I presonally prefer
>  $results=`/path/to/bash/script 2>&1`;

Also, if the command being executed takes arguments, I definitely prefer
system():

system("/path/to/bash/script", $arg1, $arg2, ...);

This avoids problems if the arguments contain any shell metacharacters.

--

Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

 
 
 

Question: Use a Perl Script to Make a Call to a Bourne Shell Script?

Post by Jason Baughe » Mon, 17 Jun 2002 22:56:50







>> > ...
>> > > Thanks for the reply - that worked great, however, now it's
>> > > executing so fast that it's running my bourne shell script before
>> > > it is completely written.  How would I go about inserting a pause
>> > > for 30 seconds in the
>> perl
>> > > script?

>> > Can't you just do things sequentially instead of waiting an
>> > arbitrary amount of time?

>> > --
>> > --Ed L Cashin            |   PGP public key:

>> It takes longer for the Bourne Shell to be written to the file then
>> it does for the Perl script to step through the code and run the
>> Bourne Shell, causing the file to be malformed and execute with
>> errors...Any ideas?

> I must not understand what you mean.  Usually you don't write the
> Bourne shell script to a file on the fly, but here's an example of
> doing just that sequentially from a perl script:

>   #! /usr/bin/perl -w

>   use strict;

>   &go;

>   sub go {
>       my $shfile = "/tmp/test-bourne.sh";

>       open SHFILE, "> $shfile" or die "Error: could not open $shfile";

>       print SHFILE "#! /bin/sh\n"
>         . "echo 'hi there!!!'\n";
>       close SHFILE;
>       chmod 0755, $shfile;

>       system $shfile;
>   }

> ... and it works just like you'd expect:


>   hi there!!!

I think what he is trying to say is that the Perl program writes to the
bourne shell file, but the O/S has not finished flushing the data to the
disk before the Perl program then tries to execute the bourne shell file.  
Therefore the file is not completely written at the time of execution.  
You need something to force it to flush the data to the disk and wait
until it is done before moving on.  

Perl experts, any ideas?

--
Jason Baugher
Virtual Adept Professional Consulting Services
1406 Adams St.
Quincy, IL 62301
(217) 221-5406
http://baugher.pike.il.us/virtualadept

 
 
 

Question: Use a Perl Script to Make a Call to a Bourne Shell Script?

Post by Barry Margoli » Wed, 19 Jun 2002 04:37:35




Quote:>I think what he is trying to say is that the Perl program writes to the
>bourne shell file, but the O/S has not finished flushing the data to the
>disk before the Perl program then tries to execute the bourne shell file.  
>Therefore the file is not completely written at the time of execution.  
>You need something to force it to flush the data to the disk and wait
>until it is done before moving on.  

>Perl experts, any ideas?

The Perl script should close() the filehandle when it's done writing the
Bourne shell script file.  This will flush its buffers.

--

Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

 
 
 

Question: Use a Perl Script to Make a Call to a Bourne Shell Script?

Post by chew » Wed, 19 Jun 2002 12:37:17


for Aristotle problem, he should just stick to system() call.
Reason: he needs his job to run sequentially.
Wat I read abt System() is that it will wait for the current job to finish
first b4 runnin the next.

Hope this helps :)