pause bash script unitil blank cd inserted in burner?
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
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: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,233
Rep:
pause bash script unitil blank cd inserted in burner?
is it possible to pause execution of a bash script at a predetermined spot and use a while loop of some nature to poll the status of the burner for presence of a cd and an if statement that either continues the script or if not blank echoes 'not a blank disc' and ejects it and continues waiting?
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,233
Original Poster
Rep:
sorry, maybe i should be more specific
i've writtin a script to automate the process of converting multiple sequentially numbered avi files to MPG with mencoder and ffmpeg (yes i know usually just ffmpeg should work but i have encountered instances where it doesnt, however i havnt failed with mencoder then ffmpeg and on a quad core phenom the extra amount of time for mencoder at like 300 some fps is negligible), at the same time echos out the necessary XML info for dvdauthor into a dvdauthor.xml file then images the dvd with dvdauthor once the conversion process finishes, once the image mastering process is finished it burns the disk
however i would like to further the automation by having it get to the point where it finishes burning the disc, then starts then goes into a wait state until a new blank is inserted (perhaps by querying the status of the drive using cdrecord and if the disc is not blank or there is no disc in the drive), enter an infinite loop that queries the drive every few seconds UNTIL a blank is inserted then starts the next set, etc... until it runs out of avi files.
sorry, maybe i should be more specific
i've writtin a script to automate the process of converting multiple sequentially numbered avi files to MPG with mencoder and ffmpeg (yes i know usually just ffmpeg should work but i have encountered instances where it doesnt, however i havnt failed with mencoder then ffmpeg and on a quad core phenom the extra amount of time for mencoder at like 300 some fps is negligible), at the same time echos out the necessary XML info for dvdauthor into a dvdauthor.xml file then images the dvd with dvdauthor once the conversion process finishes, once the image mastering process is finished it burns the disk
however i would like to further the automation by having it get to the point where it finishes burning the disc, then starts then goes into a wait state until a new blank is inserted (perhaps by querying the status of the drive using cdrecord and if the disc is not blank or there is no disc in the drive), enter an infinite loop that queries the drive every few seconds UNTIL a blank is inserted then starts the next set, etc... until it runs out of avi files.
Umm.. so yeah, why wouldn't a sleep command work in a while loop? Have it check for disc, no disc, sleep for 1 minute.. check again.. no disc, let's sleep again for 1 minute.. hey, let's see if this lazy schmuck has put in a disc yet.. oh there it is, glad he's still awake.. let's continue burning data to this new disc..
the user must be in front of the console to insert a blank CD, so he/she can always press a key to continue when ready. Then you can check if the CD is blank or not or directly try the cdrecord command and if it fails repeat again until the image is correctly burned onto the cd.
I did some quick research and it seems that HAL detects something each time that a blank cdrom is inserted. A visible difference is that the hal-device output will contain this string: "volume_empty_cd_r".
So, we could use that. Not clean, but it will work. Something in the lines of:
Code:
$ while ! hal-device | grep volume_empty_cd_r
> do
> sleep 5
> done; echo "you inserted a blank cd"
# here I pressed enter and after that, I inserted a blank cd
0: udi = '/org/freedesktop/Hal/devices/volume_empty_cd_r'
info.udi = '/org/freedesktop/Hal/devices/volume_empty_cd_r' (string)
you inserted a blank cd
I guess that there must exist a cleaner solution, involving hal or maybe dbus, to do this. However, I am not an expert in either of those. At most I can write udev rules but I haven't used so much the userland tools shipped with either hal or dbus. But while you wait for a better response, I guess that this will do.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.