Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Distribution: Mandrake 10, Debian, Slackware, Probably tried them all
Posts: 10
Rep:
cdrecord script for multiple cd-rw drives
Hi,
I'm trying to convince my company that rather than spending hundreds or even thousands of dollars on a cd-duplicating system and/or software that they should let me develop a Linux-based solution built on cdrecord. I was wondering if anybody out there has or knows where I can find an already-written script which would save me the trouble of writing a script to initialize multiple sessions of cdrecord to burn a single iso image onto 4 FireWire cdrw drives simultaneously, spit the disks out, wait for another, and start the process over again automatically? If so, that would save me a LOT of time and frustration writing the script myself as I have only a little bash experience and not a lot of spare time to work programing bugs. Thanks in advance for any help you can offer with this.
I'm working on this myself - I thought it should be something interesting to do on a Tuesday night. I should have something in a couple of hours (if that).
-----
----- This script is now maintained here.-----
-----
Dave
Last edited by ilikejam; 07-16-2008 at 02:58 PM.
Reason: Script is production ready - given its own page
Install the 'cdstatus' program from my website at: http://www.ilikejam.dsl.pipex.com/cdstatus.tar.gz
cdstatus is used to get (unsurprisingly) the status of the cd drive, i.e. whether there is a cd in the drive, or whether the tray is open etc.
Untar the archive, then do:
Code:
make
su
make install
The cdstatus utility is not my program - I got it from sourceforge at: http://cdstatus.sourceforge.net/ but the version I got didn't build properly because of a missing line in the source which I've fixed in the version from my website. Such are the joys of open source.
Once that's installed, use the following script:
Code:
#!/bin/bash
ISOFILE=$1
burndrive()
{
while true
do
sleep 2
STATUS=`cdstatus --drive $1`
echo $STATUS | grep "The drive reads disc ok. Attempting to retrieve disc info. Unable to read disc type info. Function not implemented." &> /dev/null
if [ $? == 0 ]
then
echo "Blank CD loaded on $1. Continuing."
cdrecord --eject dev=$1 $ISOFILE &> /dev/null
if [ $? == 0 ]
then
echo "Burning completed successfully on drive $1."
echo "Insert a blank disc to continue on $1."
fi
fi
done
}
for go in $*
do
if [ $go == $1 ]
then
echo -n
else
burndrive $go &
fi
done
while true
do
sleep 100
done
Call the script whatever you like and make it executable. It should be invoked with the following syntax (assuming the script is called 'multiburn')
Code:
multiburn name-of-ISO-image.iso <devices>
On my machine with two CD/DVD burners, I would use:
The script waits for blank CDs in each specified drive, and when it's done recording spits the CD out. Just put in a new blank CD to continue.
I have no experience of using Firewire cd-burners, but I would imagine they come up as SCSI drives, so you'll have to specify the correct drives in <devices> just as you would normally with cdrecord. You can specify as many cdwriter devices as you need to.
I can't be sure how firewire drives will react when probed for their status, but I'm pretty sure they work in the same way as SCSI drives, so you should be OK.
There is only one problem with the script. That is: bash creates a new process for every function that a script launches. This being the case you'll have to issue a killall to stop all the processes. e.g. if the script is called 'multiburn' then to stop all the processes (one for each burner), you'll have to do:
Code:
killall -9 multiburn
This is only a minor inconvenience, but the script will only appear to have been killed, but will still be running, if you just do a Ctrl-C to stop it. It's the nature of bash. I'm sure there must be a way round this, but I can't find it - I've tried trapping signals, locking, you name it. The easiest solution is just to make sure you killall -9 <scriptname> when you're finished.
If you accidentally put in an already burned CD into one of the drives, the script won't complain, but it will won't do anything untoward either.
So, to recap, install cdstatus: copy and paste the script and make it executable: call the script with <scriptname> <image.iso> <device list>: when you're done, do killall <scriptname>.
That program sounds interesting so I thought I'd give it a try. It runs ok and does know the cdrom is there but doesn't ever seem to start recording. All I see is ... Blank CD loaded on /dev/cdrom1. Continuing. forever.
It does stop when I eject the cdrom and starts up again when I close it.
I'm wondering if it's because of the cdrecord line which reads... cdrecord --eject dev=$1 which would mean dev=/dev/cdrom1
Normally when I do a cdrecord, it uses dev=0,0,0
I'm running FC1
Would you have any ideas on this and what kind of work around?
The reason it keeps repeating "Blank CD loaded on /dev/cdrom1. Continuing." is that ccdrecord isn't working on /dev/cdrom1, so when if fails, the function just keeps trying. You're probably still on the 2.4 kernel, so it's expecting a SCSI address like 0,0,0 - these devices don't exist on the /dev/ filesystem for cdstatus to check though.
Try using /dev/scd0 instead of /dev/cdrom1 (/dev/cdrom1 may still be pointing to the ATAPI /dev/hdx device, so cdrecord may like the scsi pseudo device /dev/scdx better).
If that doesn't work, then I'll have to do some fine tuning.
Dave.
P.S.
replace:
Code:
if [ $? == 0 ]
then
echo "Burning completed successfully on drive $1."
echo "Insert a blank disc to continue on $1."
fi
with:
Code:
if [ $? == 0 ]
then
echo "Burning completed successfully on drive $1."
echo "Insert a blank disc to continue on $1."
else
echo "Cdrecord failed on $1."
fi
then you'll be able to see whether cdrecord did anything.
I've got a better solution this time. You can uninstall cdstatus. This version uses cdrecord to check the status of the drives, so there should be no problem using the 0,0,0 syntax.
Code:
#!/bin/bash
#Copyright David Stark 2004
#Do what you like with this software. Just keep my name on it.
ISOFILE=$1
burndrive()
{
echo "Please insert a blank CD into $1 to begin."
while true
do
sleep 2
STATUS=`cdrecord -V --inq dev=$1 2>&1`
echo $STATUS | grep "medium not present" &> /dev/null
if [ $? != 0 ]
then
echo "CD loaded on $1. Continuing."
cdrecord --eject speed=4 dev=$1 -data $ISOFILE &> /dev/null
case $? in
0)
echo "Burning completed successfully on drive $1."
echo "Insert a blank disc to continue on $1.";;
254)
echo "Disc in $1 is not blank."
echo "Please insert a blank disc in $1.";;
*)
echo "Unknown error on $1.";;
esac
fi
done
}
for go in $*
do
if [ $go == $1 ]
then
echo -n
else
burndrive $go &
fi
done
while true
do
sleep 100
done
Call the script in the same way as the last attempt:
multiburn image.iso "0,0,0" ("0,1,0" "0,2,0" .....)
That works pretty slick. I wonder if the /dev/cdrom would still work in a situation where it did work using the other script. Also, I'm guessing that Ctrl C is ok now instead of killall -9 cdburn ??
Glad it's working. Yeah, you can use any device with this script that you could use in the 'dev=???' argument when you use cdrecord directly.
If you've got a 2.6 kernel, and a relatively new version of cdrecord, then you can use /dev/hdc, or /dev/cdrom, or /dev/dvd or whatever as devices depending on the setup.
Since you're using Fedora Core 1, I'd imagine you're still on the 2.4 kernel, so all the devices you use will have to be of the x,y,z style. (I'm sure you're already aware of cdrecord --scanbus)
Unfortunately the Ctrl-C problem is not fixed, so you'll still have to do killall <nameOfScript> when you're done. That's really annoying me, but I can't see any way round it.
Hi,
Thanks for your trouble. I do have the 2.4.22 kernel at the moment.
I added another cdrom recorder, added a line to the grub.conf ( hdd=ide-scsi ) and it showed up fine in the cdrecord --scanbus.
Then I ran the script ..... cdburn /home/myfile.iso "0,0,0" "0,1,0"
It works great! I realize that something like this would have more value on a bunch of recorders, but that's out of reach for now. At any rate, I like to try new and different ideas and that is one of the biggest attractions to linux for me. There is no end to the programs and projects that a person can check out. Kinda like a kid in a candy store, I guess.
I realize that something like this would have more value on a bunch of recorders, but that's out of reach for now.
Yeah, the original poster (I actually hadn't noticed that you weren't the person who started the thread) was wanting a solution for 4 Firewire drives. I hope Avian00 is still watching this thread, because I'd like to know if this works for him/her.
I've sorted out the Ctrl-C problem, so the script exits cleanly (although doing Ctrl-C kills all recording immediately, so only use it when you're finished), I've added a '-h / --help' part, and I've commented bits of the code.
I'm sure anyone watching this thread has thoroughly lost interest by now, but the limitations of my previous efforts were annoying me.
Here it is. Enjoy.
Code:
#!/bin/bash
#Copyright David Stark 2004
#Program to initiate cdrecord on multiple devices, recording on successive
#blanks until SIGINT (Ctrl-C) is received.
#User help
if [ $# == 0 ] || [ $1 == "-h" ] || [ $1 == "--help" ]
then
echo "This program starts cdrecord to burn one image file to multiple devices,"
echo "ejecting the cd when recording has finished. When a blank CD is inserted"
echo "into any of the specified drives, recording of the image begins again."
echo ""
echo "Usage: $0 image devicelist"
echo ""
echo "'image' is the name of the image to be burned."
echo "'devicelist' must be a list of devices which cdrecord understands -"
echo " see 'man cdrecord' for details."
echo ""
echo "Do Ctrl-C to terminate when recording is finished."
exit 0
fi
#Arg check
if [ $# -le 2 ]
then
echo "Not enough arguments. See '$0 -h' for help."
exit 1
fi
if ! [ -e $1 ]
then
echo "$1 does not exist. Exiting."
exit 1
fi
ISOFILE=$1
burndrive()
{
echo "Please insert a blank CD into $1 to begin."
while true
do
sleep 2
STATUS=`cdrecord -V --inq dev=$1 2>&1`
echo $STATUS | grep "medium not present" &> /dev/null
if [ $? != 0 ]
then
echo "CD loaded on $1. Continuing."
cdrecord --eject dev=$1 -data $ISOFILE &> /dev/null
case $? in
0)
echo "Burning completed successfully on drive $1."
echo "Insert a blank disc to continue on $1.";;
254)
echo "Disc in $1 is not blank."
echo "Please insert a blank disc in $1.";;
*)
echo "Unknown error on $1.";;
esac
fi
done
}
for go in $*
do
if [ $go == $1 ]
then
echo -n
else
burndrive $go &
PIDLIST="$PIDLIST $!" #Collect subshell PIDs
fi
done
#Kill subshells, then exit
trap "kill -9 $PIDLIST; exit 0" SIGINT
#This sleep loop is just to retain control of the console -
#for message output, and to catch Ctrl-C
while true
do
sleep 1000
done
Oops. A single character wrong. Here it is (again):
Code:
#!/bin/bash
#Copyright David Stark 2004
#Program to initiate cdrecord on multiple devices, recording on successive
#blanks until SIGINT (Ctrl-C) is received.
#User help
if [ $# == 0 ] || [ $1 == "-h" ] || [ $1 == "--help" ]
then
echo "This program starts cdrecord to burn one image file to multiple devices,"
echo "ejecting the cd when recording has finished. When a blank CD is inserted"
echo "into any of the specified drives, recording of the image begins again."
echo ""
echo "Usage: $0 image devicelist"
echo ""
echo "'image' is the name of the image to be burned."
echo "'devicelist' must be a list of devices which cdrecord understands -"
echo " see 'man cdrecord' for details."
echo ""
echo "Do Ctrl-C to terminate when recording is finished."
exit 0
fi
#Arg check
if [ $# -lt 2 ]
then
echo "Not enough arguments. See '$0 -h' for help."
exit 1
fi
if ! [ -e $1 ]
then
echo "$1 does not exist. Exiting."
exit 1
fi
ISOFILE=$1
burndrive()
{
echo "Please insert a blank CD into $1 to begin."
while true
do
sleep 2
STATUS=`cdrecord -V --inq dev=$1 2>&1`
echo $STATUS | grep "medium not present" &> /dev/null
if [ $? != 0 ]
then
echo "CD loaded on $1. Continuing."
cdrecord --eject dev=$1 -data $ISOFILE &> /dev/null
case $? in
0)
echo "Burning completed successfully on drive $1."
echo "Insert a blank disc to continue on $1.";;
254)
echo "Disc in $1 is not blank."
echo "Please insert a blank disc in $1.";;
*)
echo "Unknown error on $1.";;
esac
fi
done
}
for go in $*
do
if [ $go == $1 ]
then
echo -n
else
burndrive $go &
PIDLIST="$PIDLIST $!" #Collect subshell PIDs
fi
done
#Kill subshells, then exit
trap "kill -9 $PIDLIST; exit 0" SIGINT
#This sleep loop is just to retain control of the console -
#for message output, and to catch Ctrl-C
while true
do
sleep 1000
done
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.