CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Intermediate:
Automatically determing harddrive information such as filesystem type?


New User

Aug 4, 2009, 5:16 PM

Post #1 of 2 (937 views)
Automatically determing harddrive information such as filesystem type? Can't Post


I am trying to create a script that will automatically determine the source and destination drives for making images. I have some known variables such as file system type and one drive, the source, will have a boot flag. I thought that the "df" command would solve my problem and works great on a local system but when I run it from a live cd environment it will only report the cd's information, makes sense I guess. I put what I have below: I have tried to do the same thing with "fdisk -l" and split but all I can get is the last line of the output of the fdisk command. Any ideas on what to do to make such a thing work in a live cd environment? Maybe I am going about it too difficult? The goal here is that someone could boot to a live CD that runs the script and determines what the source, internal drive, and destination, external drive, is and pass that to "dd"

open (df, "df -t ext 3 |"); #I will eventually change this to ntfs
while (<df>)


$src = substr ($src, 5,3);
print "The Source Drive is $src\n";

open (df, "df -t vfat |");
while (<df>)

$dst= substr ($dst, 5,4);

print "The Destination Drive is $dst\n";

#pass those to dd and make image

New User

Aug 5, 2009, 7:23 AM

Post #2 of 2 (922 views)
Re: [jm8254og] Automatically determing harddrive information such as filesystem type? [In reply to] Can't Post

I am trying to replicate this bash loop in perl

for disk in /dev/[sh]d[a-z]; do
eval `udevinfo -q env -n $disk`
[ "$ID_BUS" = "usb" ] && EXTERNAL_DISKS=( ${EXTERNAL_DISKS[@]} $disk )
[ "$ID_BUS" = "scsi" ] && INTERNAL_DISKS=( ${INTERNAL_DISKS[@]} $disk )

something like:

$disk = /dev/[sh]d[a-z];

while (disk exist in /dev loop)


$diskID = `udevadm info -q env -n $disk | grep ID_BUS `;


Then it either list the $diskID by ID_BUS or builds an array like the above bash script. I should only have one internal and one external at any given time for what I am doing. Any ideas?

(This post was edited by jm8254og on Aug 13, 2009, 10:51 AM)


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives