List all hard drives on system (with capacities)... How?

2012-12-06 Thread Ronald F. Guilmette

I'd like to write a small program or shell script that simply lists all
of the physical hard drives attached to the local system, along with their
product identifiers and their respective capacities.

The following simple script works well for both PATA/SATA and USB hard drives,
but it does not list drive capacities:

#!/bin/sh

atacontrol list | grep ':  ad[0-9]' | sed 's/^.*:  //'
camcontrol devlist | grep '(da[0-9]' | sed -E 's/^(.*) \((da[0-9]+).*$/\2 \1/'


How can I modify the script above in order to get it to print out the
respective drive capacities?
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: List all hard drives on system (with capacities)... How?

2012-12-06 Thread Tim Daneliuk

On 12/06/2012 05:30 PM, Ronald F. Guilmette wrote:


I'd like to write a small program or shell script that simply lists all
of the physical hard drives attached to the local system, along with their
product identifiers and their respective capacities.

The following simple script works well for both PATA/SATA and USB hard drives,
but it does not list drive capacities:

#!/bin/sh

atacontrol list | grep ':  ad[0-9]' | sed 's/^.*:  //'
camcontrol devlist | grep '(da[0-9]' | sed -E 's/^(.*) \((da[0-9]+).*$/\2 \1/'


How can I modify the script above in order to get it to print out the
respective drive capacities?


Look into fdisk -s


--

Tim Daneliuk tun...@tundraware.com
PGP Key: http://www.tundraware.com/PGP/

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: List all hard drives on system (with capacities)... How?

2012-12-06 Thread Ronald F. Guilmette

In message 50c12b6c.5020...@tundraware.com, 
Tim Daneliuk tun...@tundraware.com wrote:

On 12/06/2012 05:30 PM, Ronald F. Guilmette wrote:

 I'd like to write a small program or shell script that simply lists all
 of the physical hard drives attached to the local system, along with their
 product identifiers and their respective capacities.

 The following simple script works well for both PATA/SATA and USB hard drive
s,
 but it does not list drive capacities:

 #!/bin/sh

 atacontrol list | grep ':  ad[0-9]' | sed 's/^.*:  //'
 camcontrol devlist | grep '(da[0-9]' | sed -E 's/^(.*) \((da[0-9]+).*$/\2 \1
/'


 How can I modify the script above in order to get it to print out the
 respective drive capacities?

Look into fdisk -s


Thank you Tim.

Silly me!  Before I even got your reply, I had already doen a bit more research
and I had found what I think may perhaps be an even better answer.

I never knew about this utility program called diskinfo, but I just now
found it, and it seems to do the trick.

There appears to be a small problem with using fdisk -s... It looks like it
hiccups when and if the drive in question has not actually been partitioned
yet:

# fdisk -s /dev/ad6
fdisk: invalid fdisk partition table found


(The diskinfo utility apparently does not suffer from this problem.)
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: List all hard drives on system (with capacities)... How?

2012-12-06 Thread Nikos Vassiliadis

On 12/7/2012 1:34 AM, Tim Daneliuk wrote:

On 12/06/2012 05:30 PM, Ronald F. Guilmette wrote:


I'd like to write a small program or shell script that simply lists all
of the physical hard drives attached to the local system, along with
their
product identifiers and their respective capacities.

The following simple script works well for both PATA/SATA and USB hard
drives,
but it does not list drive capacities:

#!/bin/sh

atacontrol list | grep ':  ad[0-9]' | sed 's/^.*:  //'
camcontrol devlist | grep '(da[0-9]' | sed -E 's/^(.*)
\((da[0-9]+).*$/\2 \1/'


How can I modify the script above in order to get it to print out the
respective drive capacities?


Look into fdisk -s




I think fdisk should need a valid partition table, or not?

diskinfo works nice with all disk-like devices be it a physical disk,
a slice, a partition, a swap-backed device etc. Its output is easily
parsable using a single line per device and if you use -v you will get
the same info in human-readable form.

HTH, Nikos

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: List all hard drives on system (with capacities)... How?

2012-12-06 Thread Chad Perrin
On Thu, Dec 06, 2012 at 04:23:54PM -0800, Ronald F. Guilmette wrote:
 
   if ($bytes = (1024 * 1024 * 1024 * 1024)) {

You know about the exponentiation operator in Perl -- right?

if ($bytes = (1024 ** 4)) {

I don't think typing 1024 four times with * between each pair is really a
helpful form of verbosity.

-- 
Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ]


signature.asc
Description: Digital signature