#!/usr/local/bin/expect -- set tapedev [lrange $argv 0 0] set force_conservative 0 ;# set to 1 to force conservative mode even if ;# script wasnt run conservatively originally if {$force_conservative} { set send_slow {1 .1} proc send {ignore arg} { sleep .1 exp_send -s -- $arg } } proc chtape {} { global NTAPE global tapedev set NTAPE [ expr $NTAPE + 1 ]; if [ catch { exec rm $tapedev ; } ] { puts "." ; } if [ catch { exec ln -s /arch_lvl_0_tape_${NTAPE} ${tapedev} ; } ] { exec "echo 'Chtape: Error relinking TAPEDEV' "; exec "pkill expect" } } cd set NTAPE 0; chtape; set timeout -1 spawn $env(SHELL) match_max 100000 send -- "ontape -r\r" expect "Please mount tape 1" send -- "\r" expect "Continue restore? (y/n)" send -- "y\r" expect "Do you want to back up the logs? (y/n)" send -- "n\r" # # BACKUP DATABASE # if [ catch { set NTAPE 1; expect { "Do you want to restore log tapes? (y/n)" { send "n\r"; exp_continue; } "Restore a level 1 archive" { send "n\r"; exp_continue; } "could not read archive tape" { send " echo Tape error: bad file?"; send "exit"; } "Please mount tape" { chtape; send "\r"; exp_continue; } "could not fork server" { perror "Expect encountered COULD NOT FORK SERVER"; } "user authentication failed" { send " echo Error: ontape returned user authentication failed"; send "exit"; } "incompatible state" { send "echo Error: ontape returned incompatible state"; send "exit"; } "Program over." { send "pkill -9 rest_inf.exp"; send "pkill -9 expect"; abort; send "exit"; } timeout { send "echo Expect timed out after $timeout seconds"; send "exit"; } eof { send "echo Expect encountered EOF"; send "exit"; } } } ] { send " echo Catch error during ontape command execution"; }