2

I'm running Amanda for my backups. I need to restore a bunch of files from different dates. The files have the same name so I need to do multiple restore sessions. So, I thought I'd script the thing. Here's my script:

sethost myhost
setdisk /var
setdate 2017-03-25-01-30-01
cd log/httpd
ls
add ssl_request_log
extract

I run the script using shell redirection:

amrecover my_Config < /home/me/thatScript

The problem is that as soon as amrecover sees the extract command it asks me to confirm.

Continue? [Y/n]:

Putting "Y" in the line after "extract" doesn't work. Amrecover sits there and waits for me to type "Y". I imagine amrecover is wanting the input from the tty and not just from stdin.

I've looked at the man page for amrecover and also I've google to see if someone has figured this out. And, the code is compiled so I can't hack a script to not wait for confirmation.

Is there a way to take input from both a script and redirect /dev/tty to stdin?

2 Answers 2

3

amrecover is intended to be an interactive script, so traditionally to automate it you can use expect. This tcl utility can be made to check the conversation for the two styles of prompt (amrecover> and Continue? [Y/n]:) and reply to them differently. For example, create a file myrecover in your PATH, make it executable (chmod +x myrecover) and put the following in it:

#!/usr/bin/expect
spawn amrecover my_Config 
expect   -ex {Continue? [Y/n]:}  { send "y\r"; exp_continue } \
         -ex {amrecover>}        { gets stdin input; 
               if ![eof stdin] { send $input; send "\r"; exp_continue } }
close
wait

Then run it as

./myrecover </home/me/thatScript

The expect script forks and runs your command amrecover my_Config, connecting to it via a pty, then listens to the input looking for the two prompts. When the usual amrecover> prompt is seen, we read a line from the stdin of the expect script, i.e. your set of commands, and (if we did not get end-of-file) send that line to the program, with a newline (\r gets converted to this). The exp_continue makes the command loop again for the next prompt match. On end-of-file we close the connection to the program and wait for it to exit.

Beware that running amanda this way may cause havoc if the continue prompt is for some exceptional condition etcetera.

1
  • Ah, it's been many years since I've used expect and totally forgot about it. That's the answer. Thank you!
    – Sol
    May 21, 2017 at 19:29
0

Provide the input to the extract utility via the heredoc as shown:

extract - <<\__DATA__
Y
__DATA__
1
  • That doesn't work. I get "Invalid argument." The problem, I suspect, is that amrecover is not a shell command; it's a command within a program.
    – Sol
    May 21, 2017 at 2:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .