in reply to Open a file of a different user
#!/usr/bin/perl use strict; use warnings; use Expect; $TIMEOUT = 60; $USERNAME = '(hidden)'; $PASSWORD = '(hidden)'; $PROMPT = '%'; my $exp = new Expect; $exp->exp_internal(1); $exp->raw_pty(1); $exp->log_stdout(0); my $command = '/bin/su'; my @parameters = ( '-', $USERNAME ); $exp->spawn( $command, @parameters ) || die "cannot spawn \"$command:\ +" $!\n"; $exp->expect( $TIMEOUT, [ qr/password:\s*/i => sub { my $exp = shift; $exp->send($PASSWORD); exp_continue; } ], [ qr/$prompt/i => sub { my $exp = shift; $exp->send($AWK); exp_continue; } ], [ eof => sub { die "ERROR: could not spawn $command.\n"; } ], [ timeout => sub { die "Timed out.\n"; } ], ); $exp->soft_close(); exit(0);
|
|---|