As scriptB is interactive, I've set $exp->interact.
You'll have to somehow find a way to quit the requested interactive mode of the root shell, either by interactively typing "exit", or putting the exit on the same line right after the dummy.pl:
my $result = $exp->send("dummy.pl ; exit\n");
or by replacing the shell process with dummy.pl, in which case the end of the su-session will be when the Perl program ends. I.e., try to exec the command (works for me):
my $result = $exp->send("exec dummy.pl\n");
Alternatively, you might also just use sudo to run the command (with NOPASSWD configured for whoever is supposed to run the command - see 'man sudoers' for details) — which would also be preferable from a security point of view...
In reply to Re: Switching to non/interactive mode with Expect.pm
by almut
in thread Switching to non/interactive mode with Expect.pm
by daphnaw
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |