[ Date Index ][
Thread Index ]
[ <= Previous by date /
thread ]
[ Next by date /
thread => ]
On Sat, 7 Aug 2004 11:44:02 +0100 paul sutton <zen14920@xxxxxxxxx> wrote:
#!/bin/sh
echo "camera mounting and copy routine"
#root check
if [ "$UID" -ne 0 ]
then
echo "YOU ARE NOT RUNNING AS ROOT"
exit 1
else
echo "$(date) you are running as root, mounting and copying files"
echo
fi
mount /dev/sda1 /media/camera
ls -l /media/camera
cp /media/camera/*.* /home/pausut/camera/
ls -l /home/pausut/camera
echo
echo done
exit 1
I get the following error message, I don't understand the bit about cannot
stat
mount: /dev/sda1 is not a valid block device
total 0
cp: cannot stat `/media/camera/*.*': No such file or directory
total 0
Firstly, are you using something horrible like "supermount"? I know that Mandrake
does by default as of version 8.2 (I think), but I don't know whether SuSE does too.
If it does, and you're not too worried about having to mount floppies/CDs, etc by
hand, then disable it (as root: supermount -i disable).
Secondly, I would personally have written the script a little differently:
#!/bin/bash
# A QaD script to mount and copy all the images off the camera...
#
# Set the directory to the current date:
varDESTDIR=`date +"%Y%m%d"`
if [ "$UID" -ne 0 ]
then
echo "You need to run as root!"
exit 1
else
echo "Running as root... good!"
if [ -e /dev/sda1 ]
then
mount /dev/sda1 /media/camera
case $? in
0)
echo "Mounted the device OK.";;
1)
echo "Problems mounting the device!"
exit 1;;
esac
else
echo "The camera device (sda1) doesn't seem to exist!"
echo "Please make sure the camera is plugged in..."
read -p "Press <ENTER> to verify the device name:"
fdisk -l | grep -i "sd"
exit 1
fi
echo "Making destination directory."
mkdir /home/pausut/camera/$varDESTDIR
echo "Copying files over..."
cp /media/camera/* /home/pausut/camera/$varDESTDIR/ -va
case $? in
0)
echo "Completed copying files.";;
1)
echo "Error copying files!";;
esac
umount /media/camera
exit 0
fi
#EOF
With any luck, the above would mount the device, make a new directory with the
current date, copy all the files over verbosely, recursively, and maintaining the
permissions (I prefer the -a switch over the -R switch, personal preference), and
unmount the device again. Notice that there's an "exit 0" at the end whereas I've
used "exit 1" on errors. Also note that you do not need to use "*.*", * will
suffice.
To be perfectly honest, scripts like yours and mine can very easily be extended.
For example, after the "fdisk" statement I could have put a bit to ask for user
input for the actual device name (I've not got to grips with sed/ed yet, so there's
no way I would be able to extract the device name from an fdisk call!) and then have
another go at mounting it.
Hope this helps a little.
--
Grant Sewell
BSc (Hons)
Email: grant.sewell@xxxxxxxxxx
Phone: +44 (0) 7866 065964
--
Artificial intelligence is no match for nuratal stidutipy.
--
The Mailing List for the Devon & Cornwall LUG
Mail majordomo@xxxxxxxxxxxx with "unsubscribe list" in the
message body to unsubscribe.