Re: Ontape -s , multiple tapes & cron.
Posted in 1998
Hi Jacob,
Sorry for late, I just back from holiday.
When I tried to implement my idea, I realized that there is a big problem.
When 'ontape' give prompt "Please ... continue ...", there is no CR
followed, so the 'read x' will never get this and keep waiting!
Fortunately, I worked it out with help of a small C program I call it as
'rl'. 'rl' is very simple so I believe any C compiler will compile it.
Since I don't have two tape drive on hand, I used two files for testing.
'rl' read the standard input byte by byte, it dump whole string to standard
output when it get a 'nl' character or '...'( triple dots).
$ cat rl.c#define BUFMAX 1024
main()
{
char buffer[BUFMAX+1];
int i, n, ndots=0;
for( i=0; i<BUFMAX; i++){
n = read( 0, &buffer[i], 1); # read a byte from stdin
if( n <= 0 || buffer[i] == '\\n' ) break; # return if newline or EOF
if( buffer[i] == '.' ) ndots ++; # count continuous dots
else ndots = 0;
if( ndots == 3 ){ i++; break; } # we get '...', return it.
}
buffer[i] = '\\n';
if( i == 0 && n <= 0 ){ # got nothing except EOF?
return( 1 ); # return false as 'read' behaves
}else{
write( 1, buffer, ++i ); # output whole line to stdout
return( 0 );
}
}
$ cat ontape_agent
#!/bin/sh
MAX_RETRY=5 # define maximal retry times
retry1=0 # reset counter of retries for tape 1
retry2=0 # reset counter of retries for tape 2
tapedev1=/dev/rmt/0m # I use /tmp/tape1 for test
tapedev2=/dev/rmt/0m # I use /tmp/tape1 for test
TAPEDEV=`grep '^TAPEDEV' $INFORMIXDIR/etc/$ONCONFIG | \\
sed -e 's/^TAPEDEV[ ]*//' -e 's/[ ]*#.*$//'`
while x=`rl`; do # we use our C program here
case $x in
"Please mount tape 1 on "*" and press Return to continue ...")
if [ $retry1 -eq $MAX_RETRY ]; then exit; fi
rm -f $TAPEDEV
ln -s $tapedev1 $TAPEDEV
echo
retry1=`expr $retry1 + 1`
;;
"Please mount tape 2 on "*" and press Return to continue ...")
if [ $retry1 -eq $MAX_RETRY ]; then exit; fi
rm -f $TAPEDEV
ln -s $tapedev1 $TAPEDEV
echo
retry1=`expr $retry1 + 1`
;;
"Please mount tape 2 on "*" and press Return to continue ...")
if [ $retry2 -eq $MAX_RETRY ]; then exit; fi
rm -f $TAPEDEV
ln -s $tapedev2 $TAPEDEV
echo
retry2=`expr $retry2 + 1`
;;
esac
done
$ mknod ppp p
$ ontape_agent <ppp | ontape -s -L 0 | tee ppp
Ken.