LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This 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


Reply
  Search this Thread
Old 07-26-2004, 05:39 PM   #1
Avian00
LQ Newbie
 
Registered: May 2003
Distribution: Mandrake 10, Debian, Slackware, Probably tried them all
Posts: 10

Rep: Reputation: 0
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.

Matt
 
Old 07-27-2004, 06:16 PM   #2
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 97
Hi.

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
 
Old 07-27-2004, 09:43 PM   #3
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 97
Hi again. I have a solution.

Here's how it goes:

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:

Code:
multiburn /home/dave/cdimage.iso /dev/cdrom /dev/dvd
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>.

I hope that's of some use to you.

Dave

Last edited by ilikejam; 07-27-2004 at 10:20 PM.
 
Old 07-28-2004, 08:42 AM   #4
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
Hi ilikejam,

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?

thanks,
rc
 
Old 07-28-2004, 11:12 AM   #5
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 97
Hi.

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.
 
Old 07-28-2004, 11:31 AM   #6
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
That pops up with the failure message..
Cdrecord failed on /dev/scd0

I am able to record using this line...
cdrecord -v speed=4 dev=0,0,0 -data myfile.iso
 
Old 07-28-2004, 01:06 PM   #7
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 97
Hi again.

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" .....)

Dave

Last edited by ilikejam; 07-28-2004 at 09:44 PM.
 
Old 07-28-2004, 02:25 PM   #8
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
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 ??

thanks
rc
 
Old 07-28-2004, 05:24 PM   #9
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 97
Hi again.

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.

Dave

Last edited by ilikejam; 07-28-2004 at 07:28 PM.
 
Old 07-28-2004, 07:26 PM   #10
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
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 did notice the need to use killall -9 cdburn

Anywho, it works great and love your web site.

thanks,
rc
 
Old 07-28-2004, 07:39 PM   #11
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 97
Quote:
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.

Cool.

Dave
 
Old 07-28-2004, 10:43 PM   #12
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 97
OK, so, one last time.

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
Dave

Last edited by ilikejam; 07-28-2004 at 10:50 PM.
 
Old 07-28-2004, 11:18 PM   #13
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
I didn't mean to steal the thread from Avian00 but I figured if the script works for me, then it should work for him also.

Trouble is the latest version doesn't work

/home/cdburn cd-puppy.iso "0,0,0"
or just dev=0,0,0 or 0, 0,0 or /dev/scd0 or /dev/cdrom1 will just pop the error...

Not enough arguments. See '/home/cdburn -h' for help.
 
Old 07-28-2004, 11:29 PM   #14
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 97
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
Cheers for the feedback!

Dave
 
Old 07-28-2004, 11:53 PM   #15
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
Sweet! that works great, ctrl c also.

That ole le / lt will get you every time.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Backup Script from Multiple Drives to one Big Drive robinhood1995 LinuxQuestions.org Member Success Stories 5 03-26-2005 06:17 PM
multiple drives cs-cam General 2 02-16-2005 05:46 AM
Script to run script in multiple directories... seabass55 Linux - General 5 07-06-2004 12:44 AM
Help: CDRECORD: multiple scsibuses? oswald21 Linux - Software 3 05-10-2003 12:49 AM
I've taken all the steps but cdrecord still shows no drives? Null Linux - Software 3 03-30-2003 07:39 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:48 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration