ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
i am writing a bash shell script to automate cd burning. what i'm trying to do is,
1. if a user insert a blank cd it will burn with multi session (new multi session).
2. if not the script will try to detect whether the disc inserted is multi session disc or not.
3. if the disc is multi session disc then the script will continue writing with next session.
however i have difficulty to detect if the disc is multi session disc.
One possible way to do it might be to test against the exit status of the command instead of its output.
Code:
cdrecord -msinfo dev=1,0,0 &> /dev/null
if [ $? -eq 0 ]
then
.....
The $? variable contains the exit status of the last command. This is just an idea for you to try, it may not work if, for example, the script gives you the same exit status either way.
The $? variable contains the exit status of the last command. This is just an idea for you to try, it may not work if, for example, the script gives you the same exit status either way.
yes exactly! i tried this method before..
is there anyway i can count line of the output
Code:
cdrecord -msinfo dev=1,0,0
what i thought is;
- if that command runs on MULTI SESSION cd the output of the command will be just ONE LINE
- the same command if runs on NON MULTI SESSION cd will return MORE THAN ONE LINE..
Alternately, you could leave out the redirect to omit STDERR from the word count. This is pretty simple logic though, so I'd test it with all the different situations you might run into just to make sure the program reacts as expected.
# Get info from current loaded cd
# @param string $1 Name of device containing the cd.
# @return
# @global string $cdIsMultiSession 1 if cd is multi-session, 0 if not
# @global string $cdMultiSessionInfo Format: last_sess_start,next_sess_start
# The first number is the sector number of the first sector in the last
# session of the disk that should be appended to. The second number is
# the starting sector number of the new session.
# Example values are:
# 0,-1 : readonly CD
# 0,24448 : multi-session CD with one previous session
# null : blank CD:
# @global integer $cdLastSessionStart Starting sector number of last successful written session.
# @global integer $cdNextSessionStart Starting sector number of new session.
# @global integer $cdNextSessionNr Session number of new session, origin = 0.
#
# This software is released under the terms of the GNU General Public License.
# Copyright (C) 2006 Freddy Vulto
#
# The latest version of this software can be obtained here:
# http://www.fvue.nl/wiki/Bash:_Backup_on_cdrw
#
function getCdInfo() {
# Retrieve maximum number of blocks on cd
cdMaxNrOfBlocks=`\
sudo cdrecord dev=$1 -atip 2> /dev/null |\
sed -rn 's/^ ATIP start of lead out: ([0-9]+).*/\1/ p'`
cdIsMultiSession=1
cdLastSessionStart=
cdMkisofsMultiSessionOptions=
cdMultiSessionInfo=`sudo cdrecord -msinfo dev=$1`
cdNextSessionNr=0
cdNextSessionStart=
if [ $cdMultiSessionInfo ]; then
cdLastSessionStart="`echo $cdMultiSessionInfo | awk -F, '{ print $1 }'`"
cdNextSessionStart="`echo $cdMultiSessionInfo | awk -F, '{ print $2 }'`"
cdMkisofsMultiSessionOptions="-C $cdMultiSessionInfo -M $1"
cdNextSessionNr=2 # Or greater...
if (( $cdNextSessionStart == -1 )); then
cdIsMultiSession=0
elif (( $cdLastSessionStart == 0 )); then
cdNextSessionNr=1
fi
fi
} # getCdInfo()
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.