Something along this usually works to interact with programs through perl,
this could be edited for your purpose.
This does a simple tail but you can guess the rest.

#!/usr/local/bin/perl -w
use Data::Dumper;
use File::Copy;
use IPC::Open3;
use IO::Select;
use IO::Handle;
use strict;

use vars qw(
  $line $select
  $read $write $error
);

( $select, $read, $error ) =
  process_command('/usr/bin/tail -f tmp.dat');
  process_tail($select);
close_handles( $read, $error );

sub process_command {
    my ($command) = @_;

    my ( $pid, $readbuff, $timeout, $s );
    $timeout = 10;
    $read    = new IO::Handle;
    $error   = new IO::Handle;

    $pid = open3( $write, $read, $error, $command );

    #
    # create selects
    #
    $s = IO::Select->new();
    $s->add($read);
    $s->add($error);

    return ( $s, $read, $error ); }

sub process_tail {
    my ($select) = shift;
    my ( @ready, $handle, $timeout, $readbuff, $flag, $tapeloc, $newnum );
    $flag = 0;

    #
    # get write handle
    #

    while ( $flag == 0 ) {
        @ready = $select->can_read($timeout);

        foreach $handle (@ready) {
            sysread( $handle, $readbuff, 256 ); # 256 is the number of chars
to read.
print "$readbuff";

            if ( length($readbuff) == 0 ) {
                $flag = 1;
            }
        }
        #
        # do something here
        #
        }
        sleep(1);
    }

sub close_handles {
    my ( $r, $e ) = @_;
    $r->close();
    $e->close();
}


 

-----Original Message-----
From: ppp ppp [mailto:[EMAIL PROTECTED] 
Sent: 04 September 2007 15:50
To: beginners@perl.org
Subject: Want to interactively run a shell script


Hi All,
   
       I want to remove some packages install on remote solaris through
script. I am able to run simple command like ls -l ,ls through perl script
by using Net::Telnet module.
   
  Now I want my script should remove all the packages installed on remote
solaris
   
  means i want to remove 
   
  pkgrm -R `pwd` command but the problem is that it requires user to
manually enter yes/no to remove the pkgs
   
  suppose i will issue pkgrm -R `pwd`  then it asks
   
  The follwing pkgs are install do u want to remove this package[y]
  here I required to enter y
   then it ask
  do u want to remove xxxx.pkg ?
  here also I required to enter y
   
  I need a way so that my script will send those and I don't have to enter
commands
   
  how my script will be interactive so that i can enter y through my script
  I want to run my script on my PC and the  packages are installed on a
remote Solaris box.
   
  Thanks 

       
---------------------------------
Fussy? Opinionated? Impossible to please? Perfect.  Join Yahoo!'s user panel
and lay it on us.


This e-mail is from the PA Group.  For more information, see
www.thepagroup.com.

This e-mail may contain confidential information.  Only the addressee is
permitted to read, copy, distribute or otherwise use this email or any
attachments.  If you have received it in error, please contact the sender
immediately.  Any opinion expressed in this e-mail is personal to the sender
and may not reflect the opinion of the PA Group.

Any e-mail reply to this address may be subject to interception or
monitoring for operational reasons or for lawful business practices.





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to