how to modify the output of df command
this is the output of df command on my system
Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda8 18073924 4911628 12244184 29% / udev 642140 308 641832 1% /dev none 642140 1820 640320 1% /dev/shm none 642140 332 641808 1% /var/run none 642140 0 642140 0% /var/lock none 642140 0 642140 0% /lib/init/rw /dev/sda6 39070048 37855272 1214776 97% /media/New Volume /dev/sda5 1959898 1330254 629644 68% /media/New Volume_ /dev/sdb1 15752188 12568456 3183732 80% /media/ANURUPDT /dev/sr0 8128832 8128832 0 100% /media/cdrom0 i just need to get /dev/sr0 .. is that possible using grep or cut because i tried doing that |
Hi,
You really should get some background information or references; Linux Documentation Project Rute Tutorial & Exposition Linux Command Guide Bash Reference Manual Advanced Bash-Scripting Guide Linux Newbie Admin Guide LinuxSelfHelp Getting Started with Linux These links and others can be found at 'Slackware-Links' . More than just SlackwareŽ links! |
Hi anurupr
You say you have tried grep. If you show us what you have tried we can tell you which bit is in error? Just to confirm, you basically only want to return the row(s) containing /dev/sr0? Apart from all the other references by onebuck, I would simply suggest man grep |
im not getting the right output when using cut and grep commands
i used grep and cut to get a string from the df command output
this is the shell script that i used to do it but its never exiting the while loop Code:
#!/bin/bash |
i dont want to return the entire row i jus need to return "/dev/sr0"
|
this works for me:
Code:
[liveuser@localhost ~]$ while [ $c != "/dev/sr0" ] ; do c=`df |grep "/dev/sr0"|cut -f 1-2 -d' '`; echo c = $c; sleep 1; done |
do you mean getting the first column, i.e. list of all your partitions? if so you might have some luck with sed.
if not, it might help to know what youre going to use it for, as I am a bit confused about what info you want to get from the df command. |
weird :(
|
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.
|
Quote:
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: Code:
grep '/dev/sr0' /proc/mounts | cut -f 1 -d ' ' Code:
df | grep '/dev/sr0' | cut -f 1 -d ' ' 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. |
Anurupr,
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... Cheers, Tink |
These commands:
Code:
c=`df | grep "/dev/sr0" | cut -f 1-2 -d ' '` Code:
"/dev/sr0 " Code:
"/dev/sr0" These commands: Code:
c=`df | grep "/dev/sr0" | cut -f 1 -d ' '` Code:
"/dev/sr0" |
Code:
df|awk '$1 ~ /sr0/{print $1}' |
Hi anurupr
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: Code:
while [[ ! $(df | grep -q /dev/sr0) ]] |
fyi, i put this code in my xbmc /etc/rc.local. maybe this mite help:
Code:
while [ 1 ] |
All times are GMT -5. The time now is 11:23 PM. |