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'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?
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?
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.