jcpunk has asked for the wisdom of the Perl Monks concerning the following question:
any ideas as to how to boost the performence, or an easy way of getting only some of the output off of expect, or a different module to use for this?
my $exp = Expect->spawn("su - $username") || die "Cannot spawn su: $!\ +n"; ####################################### $exp->debug(3); ####################################### $exp->raw_pty(1); my $spawn_ok; $exp->expect($timeout, [ 'Password: \$', sub { my $fh = shift; print $fh "$password\n"; $spawn_ok = "yes"; exp_continue; } ], [ eof => sub { if ($spawn_ok) { die "ERROR: premature EOF in login.\n"; } else { die "ERROR: could not spawn su.\n"; } } ], [ timeout => sub { die "Login process timed out\n"; } ], # ); #$exp->expect($timeout, # [ '-re', qr'[#>:] \$', sub { if($spawn_ok eq "yes") { if($on_off eq "on") { foreach $FILENAME (@list_of_files) { $exp->send("/bin/touch /home/$username/$FI +LENAME"); if ( $FILENAME eq ".forward") { #.forward must look like \username, + "|/usr/bin/vacation username" $set_fwd="\\$username, \"|/usr/bin/vac +ation $username\""; $exp->send("/bin/echo $set_fwd > /home +/$username/$FILENAME"); } if ( $FILENAME eq ".vacation.msg") { $message .= '\n'; $exp->send("/bin/echo $message > /home +/$username/$FILENAME"); } $exp->send("/bin/chmod 644 /home/$username +/$FILENAME"); $exp->send("/bin/chown $username /home/$us +ername/$FILENAME"); } if($on_off eq "off") { foreach $FILENAME (@list_of_files) { $exp->send("/bin/rm -f /home/$username +/$FILENAME"); } } } } } # ], # [ # timeout => # sub { # die "Login process timed out\n"; # } # ], );
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Faster way to do su
by Fletch (Bishop) on Apr 16, 2004 at 20:48 UTC | |
by jcpunk (Friar) on Apr 16, 2004 at 21:49 UTC | |
|
Re: Faster way to do su
by matija (Priest) on Apr 16, 2004 at 22:48 UTC | |
|
Re: Faster way to do su
by b10m (Vicar) on Apr 16, 2004 at 20:49 UTC | |
by jcpunk (Friar) on Apr 16, 2004 at 22:01 UTC | |
by Fletch (Bishop) on Apr 16, 2004 at 23:33 UTC |