Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
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.
There is less than 24 hours left to vote in the 2015 LinuxQuestions.org Members Choice Awards. Click here to go to the polls. Vote now and make sure your voice is heard!
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
what im trying to do is detect if a cd is inserted or not . when a cd is inserted and the df command is used /dev/sr0 (or /dev/scd0) appears in the output but is absent when a cd is not inserted . so i basically exploit this to check if a cd is available or not.
These links and others can be found at 'Slackware-Links' .
More than just SlackwareŽ links!
If you follow one_buck's advice, you will save yourself a lot of time. You may even be able to find some of the documents in your own native language (which I am guessing is not English).
I will, however, try to answer your question. Using "cut -f 1 -d ' '" will give you a the first row. However because the rows are not separated with a a single character separator, getting the second row (if you wanted it) would be tricky. You might want to use:
grep '/dev/sr0' /proc/mounts | cut -f 1 -d ' '
df | grep '/dev/sr0' | cut -f 1 -d ' '
I notice you have asked lots of questions but you don't seem to have said what is that you are trying to accomplish. We know you want to execute a command when a CD is mounted - but for what purpose?
Also it isn't clear if you want to execute the command once per mount or the whole time the cd is mounted.
Do you want to have a program autorun when you put the CD in your computer? If so why not just run the program manually?
Do you want to have a program autorun when you put the CD in another computer? You will have to install the autorun program you are trying to make, which kind of defeats the purpose.
I've closed one of your duplicated threads, and merged two others.
I'd recommend that you read our rules again and discontinue this
bad practice - stick with one thread, and run with it if the problem
belongs in the same scope...
It seems we are all on a bit of a goose chase here it would appear to me.
From reading this thread (and others you have posted) your only requirement
is to check that df is returning /dev/sr0 and not to actually get this information in a variable.
In this case you simply need the following:
while [[ ! $(df | grep -q /dev/sr0) ]]
<your code here>