Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

script to burn files

  • 28-12-2004 4:36pm
    #1
    Moderators, Arts Moderators Posts: 35,737 Mod ✭✭✭✭


    I'm trying to write a simple script to burn a list of files to CD at 8x speed, using mkisofs and cdrecord. I have the second part, but the man page for mkisofs confuses the bejesus out of me. Not sure what switches or options to use for best compatibility and to give the CD a name.

    Can anyone help me fill in the blanks?

    mkisofs somestuffhere file1 file2... filen "name of cd" image.iso
    cdrecord -v -pad speed=8 dev=/dev/dvd:1,0,0 image.iso


Comments

  • Technology & Internet Moderators Posts: 28,830 Mod ✭✭✭✭oscarBravo


    mkisofs -J -R -V "name of cd" -o image.iso file1 file2 ...

    Should do it


  • Moderators, Arts Moderators Posts: 35,737 Mod ✭✭✭✭pickarooney


    Yep, that's the one, cheers :)
    Now I just need to learn how to parse the input parameters from the command line so that when the user types burn "my cd" file1 file2 ... $1 gets assigned to the CD name (simple) and the rest of the parameters get added to a list (with $0 or something, but excluding $1, bit more tricky)


  • Technology & Internet Moderators Posts: 28,830 Mod ✭✭✭✭oscarBravo


    Have a look at this - I don't have time to fully figure it out right now, but it looks like $# is your friend.


  • Moderators, Arts Moderators Posts: 35,737 Mod ✭✭✭✭pickarooney


    Yep, it all goes great using $* (takes all the parameters, $# tells me how many I need to process) until I use a file with spaces in the name.
    When I pass a filename to mkisofs from the command line, as "name of file.jpg" it gets interpreted on the fly as name\ of\ file.jpg and the program can understand it and make the ISO. However, from within a script, the interpretation is skipped and mkisofs gets passed three parameters "name, of and file.jpg" which makes it cry.
    I think I need to use a combination of shift and sed to parse the filenames and pass them to mkisofs. Will try later and post the script if I get it to work.


  • Technology & Internet Moderators Posts: 28,830 Mod ✭✭✭✭oscarBravo


    Have you tried wrapping every filename in double quotes as you pass them to mkisofs? I know you're hand-wrapping the ones with spaces in when you pass them to the script, but they seem to get discarded during $* processing. If you rewrap all the filenames, you've covered your bases, no?


  • Advertisement
  • Moderators, Arts Moderators Posts: 35,737 Mod ✭✭✭✭pickarooney


    oscarBravo wrote:
    Have you tried wrapping every filename in double quotes as you pass them to mkisofs? I know you're hand-wrapping the ones with spaces in when you pass them to the script, but they seem to get discarded during $* processing. If you rewrap all the filenames, you've covered your bases, no?

    It seems to be the other way around. They get through $* intact (checked with a temp flag) but the quotes get taken literally once they're passed to mkisofs inside the script. I'll report back once I've tried sedding them.


  • Technology & Internet Moderators Posts: 28,830 Mod ✭✭✭✭oscarBravo


    Try using instead of $*?


  • Moderators, Arts Moderators Posts: 35,737 Mod ✭✭✭✭pickarooney


    Yeah, found that earlier and been using it for the last half hour or so, seems to be going fine :)
    As a matter of interest, where did you find that?


  • Technology & Internet Moderators Posts: 28,830 Mod ✭✭✭✭oscarBravo


    It's in the link I posted earlier. I'm slowly coming to grips with shell scripting myself.


  • Moderators, Arts Moderators Posts: 35,737 Mod ✭✭✭✭pickarooney


    so this is the unassuming final product:
    #!/bin/bash
    echo "Enter CD title:"
    read title
    
    mkisofs -J -R -V "$title" -o "$title".iso "$@"
    cdrecord -v -pad speed=8 dev=/dev/dvd:1,0,0 "$title".iso
    

    child's play ;)


  • Advertisement
  • Moderators, Arts Moderators Posts: 35,737 Mod ✭✭✭✭pickarooney


    Hrm, results are not so amazing - 2 out of 3 CDs are getting fsked up. I'm burning 3-4 files per image and while burning seems to complete OK, when I copy the files back to the HD the last file gives an I/O error.

    Are there any parameters I can pass to reduce the likelihood of CDs getting destroyed? The burner goes up to 52 speed, but I burn at 8 for safety's sake.
    With k3b I usually lose one in about 5 CDs, but this is just too many.

    Would the burnfree/overburn switches help?


  • Technology & Internet Moderators Posts: 28,830 Mod ✭✭✭✭oscarBravo


    I always add "driveropts=burnfree" to my cdrecord commands, and I don't think I've lost a CD yet. One in five seems like an awful lot.


  • Moderators, Arts Moderators Posts: 35,737 Mod ✭✭✭✭pickarooney


    I've a feeling the drawer might be a little off-balance. When I closed it the last couple of times there was a strange scratching sound. It's gone now, but I didn't like it! :)
    I'll try burnfree, sure I've nothing to lose (except 18 cents per CD).


  • Registered Users, Registered Users 2 Posts: 2,755 ✭✭✭niallb


    I don't think I remember losing a CD either, and I would go with the burnfree option too.
    9 times out of 10 it reports that it wasn't used.

    I know this isn't quite for a list of files,
    as I treat it in terms of directories,
    but the list of options is time tested.

    I've been using this for years to master CDs.
    Occasionally I get filename conflicts, but only on really odd CDs.
    #!/bin/sh
    USAGE=$1
    if [ "$USAGE" = "-opts" ] ; then
            echo options order: DIR IMAGE VOLID APPID PUBLID PREPID ;exit 0
    fi
    DIR=${1:-"`pwd`"}
    IMAGE=${2:-/Master/Master.iso}
    VOLID=${3:-"$DIR `date +%Y%m%d`"}
    APPID=${4:-"`hostname`"}
    PUBLID=${5:-"iso@cs-consultants.com"}
    PREPID=${6:-"$PUBLID"}
    
    echo  IMAGE : $IMAGE
    echo  DIR   : $DIR
    echo  VOLID : $VOLID
    echo  APPID : $APPID
    echo  PUBLID: $PUBLID
    echo  PREPID: $PREPID
    
    mkisofs -o $IMAGE  -l -r -D -L -J -V "$VOLID" -P "$PUBLID" -p "$PREPID" -A "$APPID"  "$DIR"
    
    

    This has more options than usually needed (at least for PC CDs), but gives a good image.
    Burning the image then can be like this:
    #!/bin/sh
    BURNERDEVICE=01,00,0
    # For data CDs
    cdrecord driveropts=burnfree -v speed=32 dev=$BURNERDEVICE -eject -data $1
    
    # For CD-RW
     cdrecord driveropts=burnfree blank=fast -v speed=8 dev=01,00,00 -eject -data $1
    
    # Overburn option if you're near the edge:
    cdrecord driveropts=burnfree -v speed=32 dev=01,00,00 -overburn -eject -data $1
    
    # For Audio CDs.
    #!/bin/sh
    SONG=${1:-'*.wav'}
    echo Recording $SONG to CD.
    cdrecord driveropts=burnfree -v speed=32 dev=01,00,0 -eject -pad -audio $SONG
    

    How you get your tracks to wav or even whether they're really wav or just wav in pipes (sorry!) is outside the scope of that script.

    cdrecord -scanbus will give you the correct BURNERDEVICE.
    I've started to keep it in a config file called by all my CD scripts, as the bus number
    changes depending on what I've plugged in via USB, so it's just one change.

    NiallB


  • Moderators, Arts Moderators Posts: 35,737 Mod ✭✭✭✭pickarooney


    I don't know if it's due to adding the driveropts=burnfree bit or just luck, but the last 7 CDs have burned OK. I'll add -overburn too, as the last few CDs haven't been more than 690MBs of data. Can overburn have undesirable effects?

    I like the audio CD burning line, can add it to my existing mp32wav script. :)


  • Registered Users, Registered Users 2 Posts: 2,755 ✭✭✭niallb


    Hi P,
    Happy New Year.

    I think I added overburn for a few CDs (I think a NetBSD disk, and definitely CD1 from Mandrake 8.2) which were 701M.
    I've never had a problem with it with my own burners, but maybe do a google for
    your own model and overburn to see if it might die!

    NiallB


Advertisement