LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-11-2005, 11:49 PM   #1
linuxchump
LQ Newbie
 
Registered: Mar 2005
Posts: 10

Rep: Reputation: 0
fdisk command, for / value / do - unsure


I've been parsing the posts here and have found some valuable information. But I'm still lost on something. I'm wanting to write a script that will identify Linux filesystems. Essentially, I was thinking of using 'fdisk' and 'mount' to obtain this information.

'fdisk -l' lists recognized partitions and a 'System Type' field (value of 'Linux' is the one I'm concerned with).

'mount -vf --guess-fstype' allows me to use 'mount' to guess the FS TYPE for a partition, without actually mounting it.

My thought was to parse the output of 'fdisk -l' and look only for entries containing 'Linux', and then run the 'mount' command above against each of those to report the Linux FS TYPE on the filesystem/partition.

I've tried IFs, FOR, and LOOPS. Nada. Zilch. I'm beyond lame at this point. I know what I want, but I'm stuck getting there. A variable could be 'type', and set that to 'Linux'. So if the output of fdisk is equal to that I want to execute the mount command. The most success has been with IF statement,

#!/bin/bash
#
#

type=Linux

if [ 'fdisk -l' = $type ]; then
mount -vf --guess-fstype > output_file
fi


Does anyone have any thoughts on the best route to take here, in writing a bash script to identify the FS TYPE for a partition?


LC
 
Old 03-12-2005, 01:12 AM   #2
dbalsige
LQ Newbie
 
Registered: Mar 2005
Location: Switzerland
Distribution: LinuxFromScratch
Posts: 5

Rep: Reputation: 0
hello

the option --guess-vfstype requires an argument
so what you might use is something like:

#!/bin/sh

guess_fs()
{
local IFS=$'\n'
for LINE in `fdisk -l | grep Linux` ; do
mount -vf --guess-fstype ${LINE%% *}
done
}

guess_fs

Last edited by dbalsige; 03-12-2005 at 01:14 AM.
 
Old 03-12-2005, 10:01 PM   #3
linuxchump
LQ Newbie
 
Registered: Mar 2005
Posts: 10

Original Poster
Rep: Reputation: 0
Hi dbalsige and all,

I see your hint and it works good. I get output;

[root@chump tmp]# ./reiser_2.sh
ext2
ext3
reiserfs
ext2
ext3
swap
[root@chump tmp]#


I have two goals though I'm working through.

ONE: Associate the device (partition) with the FS TYPE guessed by mount. (Output of FS TYPE isn't associated with any device above.)

TWO: If the FS TYPE returned is equal ot 'reiserfs' I want to run another command against that (those) reiserfs partition(s).

I'm going to work with your tip above and see where I go. Report back more soon. Thank you kindly.

LC
 
Old 03-12-2005, 10:37 PM   #4
linuxchump
LQ Newbie
 
Registered: Mar 2005
Posts: 10

Original Poster
Rep: Reputation: 0
I'm a step further in my quest, in that I now use;

#!/bin/sh

guess_fs()
{
local IFS=$'\n'
for LINE in `fdisk -l | grep Linux` ; do
blkid -c /dev/null ${LINE%% *} | grep reiser
done
}

guess_fs



That now returns more meaningful information;

[root@chump tmp]# ./reiserid.sh
/dev/sda4: LABEL="reisfs" TYPE="reiserfs"


Now for goal TWO, taking any of the reisefs identified partitions and running a command against them.

I want to run 'losetup' against reiserfs partitions. Associate each partition with a loop device. I'm wondering if I can take the output returned from part one and use that for part two?

Of course this calls for finding available loop device and associating partition with it.

I'm thinking, should I redirect the output from what I have above to a file and then parse this file for devices (/dev/hd*, /dev/sd*) and associate them to loop?

Thank you kindly,

LC
 
Old 03-13-2005, 05:56 AM   #5
gbonvehi
Senior Member
 
Registered: Jun 2004
Location: Argentina (SR, LP)
Distribution: Slackware
Posts: 3,145

Rep: Reputation: 52
I didn't understand what you're really trying to achieve, but hope this helps:

Code:
#!/bin/sh
                                                                                          
guess_fs()
{
local IFS=$'\n'
for LINE in `fdisk -l | grep Linux` ; do
    if blkid -c /dev/null ${LINE%% *} | grep reiser >/dev/null; then
        yourcommands;
    fi
done
}
                                          
guess_fs

Last edited by gbonvehi; 03-13-2005 at 05:58 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem using command fdisk -l ? AkshatBhandari Linux - Newbie 2 03-17-2005 01:36 PM
fdisk command - can't get it to work!! sknarf Linux - Software 4 06-23-2004 02:59 AM
fdisk command not found? tiang_ono Linux - Newbie 7 05-17-2004 11:48 PM
fdisk command thefetus Linux - Newbie 5 11-19-2003 03:15 PM
fdisk not a command? toob Linux - Newbie 11 04-26-2003 11:56 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:11 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration