I would like to read various partitions from a DDS tape using a script
At the moment I am using the following script
TAPE=/dev/nst0
BLOCK_SIZE=32768
COUNTER=1
END_OF_DATA=120
while [ $COUNTER -lt $END_OF_DATA ]
do
dd if=$TAPE bs=$BLOCK_SIZE of=file_$COUNTER
let COUNTER+=1
done
However, as you can see my script can read at maximum 120 partitions.
How can I modify this code to enable the script to recognise the end of data of the tape automatically
Thanks
You can keep comparing the report with block size. And yes you have to open the device only once and keep reading from it.
Script is tested with a file.
You can also remove the last file if last number of bytes read was just 0:
If you want to send a message while you process the tape, you can use redirections and use another file descriptor for it:
Example output:
Another option is to just send your
echo
s to/dev/stderr
.To make it a little faster also, use
exec
inside the subshell to prevent extra fork: