RE: Want to interactively run a shell script



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:prabhat_xyz@xxxxxxxxx]
Sent: 04 September 2007 15:50
To: beginners@xxxxxxxx
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.




.



Relevant Pages

  • Expect for Windows, missing interact, timeout...
    ... Many years ago I wrote a script using expect on a solaris system. ... spawn a telnet in an xtem to get to an application server. ... There is no Interact command: This version of Expect does not have an ...
    (comp.lang.tcl)
  • Re: Using sendkeys in a web form
    ... to interact with the GUI interface - unless you are a script. ... know where to navigate to, is MUCH harder than finding it in the raw HTML ...
    (microsoft.public.scripting.vbscript)
  • Re: [Expect] Need to have explanations for the use of the expectcommand
    ... Otherwise I think the script is OK. ... spawn ssh root@remtest1 cd logs; ... you will be able to interact with your test setup. ... I put the interact command at the end (in place of the ...
    (comp.lang.tcl)
  • Expect: interact and buffering?
    ... with the tcl application and terminated it. ... remaining output would display and the Expect script would end. ... I have changed the interact in an attempt to make it process character ...
    (comp.lang.tcl)
  • Exepect, curses, and screen control
    ... I have a script I am working on that uses the Perl expect module. ... It lets the user interact with the ... then when the user hits a control key - it leaves the ...
    (comp.lang.perl.misc)