I have this script for automating a simple process where I scan a number into the command line, grep that number out of a catalog file which gives me a path, and then copy the DVD which the above mentioned number corresponds to, to the path. The cp command keeps failing. I've looked at other posts where cp is not working in a script but they all seem to have to do with quotes around filenames. I don't think that's my problem here.
I've added some comments for I hope will turn out to be clarity:
\#!/bin/bash
\# accepts a single command line parameter: six-digit DVD number, ex. 987110
\# the empty echo lines are just whitespace for readability**
clear
file=/public/TAPES/batch1/Shipment_1_catalog.txt.dvd
echo
echo DVD number is $1
echo
echo catalogfile is $file
>\# this grep instruction greps $1 out of $file
>\# output from this is 'XXXXXX file-path-to-copy-dvd-contents-to'
>\# qwk puts the file-path... into $pth
pth=`grep $1 $file | awk ' { print $2 } '`
echo
echo destination path is $pth
echo
mount /dev/sr0 /media # appears to work
cp -p -r /media/\* $pth # this always fails - see error text below.
echo
umount /dev/sr0 && eject # this does work
Everything works except the copy command. It produces the following error output:
DVD number is 987110
catalogfile is /public/TAPES/batch1/Shipment_1_catalog.txt.dvd
destination path is > /proj/T_010/gdm/SAM/BRA/3D/Santos_ESP_3D_BDEP_2010/dvd/legacy/987110_Line_Section_Various_Vintages-Post_Stack_Migration_DVD_14_of_41
mount: block device /dev/sr0 is write-protected, mounting read-only
cp: cannot stat `/media/*': No such file or directory
The permissions for the script are 755. I've tried it as './cpy.sh' and 'bash cpy.sh' with the same results both times.
sleep 10betweenmountandcpcommand lines. When you mount a DVD it takes a few seconds to discover the contents.*? Do you really want to find a file named*and not use it as a glob?/media/*...` message.