in reply to Expect.pm and sudo.

You could play dirty and supply the input to your pre_backup script from its STDIN directly in the sudo command line:
sudo sh /usr/local/scripts/pre_backup.sh <`echo "X"`
Those are backticks, BTW.

OK, this is not exactly what you asked, but in the age old spirit of TIMTOWTDI and getting around annoying limitations that is integral to Perl, it gets the job done (I hope).

Note that, if your script expects input more than once, you'll have to modify the echo to take this into account.

Caveat: I'm not sure how expect spawns its command lines or how sudo spawns its commands, but if a shell is involved anywhere in there, you'll have to get creative with those backticks and quotes to avoid said shell stomping all over it.

CU
Robartes-

Update: Added caveat.

Replies are listed 'Best First'.
Re: Re: Expect.pm and sudo.
by sschneid (Deacon) on Oct 16, 2002 at 20:49 UTC
    Thanks very much for the help, robartes (++). Here's what I came up with, in case anyone should read this thread and want to know the (quick & dirty, at least) solution:

    sudo sh -c 'printf "\n" | sh /usr/local/scripts/pre_backup.sh'

    I'm still interested if there's an actual way to do it with the Expect.pm module (making this a bit more perl-relevant), so if anyone is clued, a heads-up would be fantastic.

    Thanks again,
    scott.
      printf "\n"? That's the same as a simple echo, no?

      Makeshifts last the longest.