How to enumerate mounted disks and place output in array ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to enumerate mounted disks and place output in array ?
# 1  
Old 02-12-2011
How to enumerate mounted disks and place output in array ?

Hi.

I'm new to scripting / programming and was wondering what the best way to output all mounted storage devices and their names to an array would be ? I would like to achieve this using the bash shell.

Any assistance with this would be greatly appreciated.

Regards,
Jonno Smilie
# 2  
Old 02-12-2011
Code:
IFS=$'\n'
array=( $(mount) )
IFS=$' \t\n'

This User Gave Thanks to cfajohnson For This Post:
# 3  
Old 02-12-2011
Ok, so I think I undertsand your reply... Let me get this straight.

Line 1 we are telling bash to separate fields based on new lines.
Line 2 we are doing command substitution on "mount" and storing the output int the array "array"
Line 3 we are setting the $IFS variable back to default ???

Only problem is for some reason I only get the first line of the mount output stored in the array when i do "echo $array"

Any suggestions ?
# 4  
Old 02-12-2011
From the bash man page:

Code:
Referencing an array variable without a  subscript
       is equivalent to referencing element zero.

(that's the first element)

Use:
Code:
${array[0]}
${array[1]}
etc.

to access individual elements, or
Code:
${array[@]}

to access all elements.

For more information, check out the man page for your shell, i.e. bash, under section Arrays.
This User Gave Thanks to Scott For This Post:
# 5  
Old 02-12-2011
Many thanks to both of you for your quick and thorough responses to my noob questions.

Regards,
Jonnno
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Grant unprivileged user rights to see the output of echo|format but not modify disks

anyone have any idea how do to this with auth_attr? I suspect if I grant him solaris.device.:RO::Device Allocation::help=DevAllocHeader.html that will work but I'm unsure. Just looking for a second opinion. (10 Replies)
Discussion started by: os2mac
10 Replies

2. Shell Programming and Scripting

Place the contents of a .CSV file to an array

Hi, I am trying to place the contents of a .CSV file to an array, but not sure how to do that. Here is my .CSV file content: App,SLA,Job name,Avg start time,Avg run time,Frequency,Downstream apps XYZ,,ABC14345,3:00 AM,00.04.00,Daily,STAMP XYZ,9:00,ABC12345,3:15 AM,00.05.00,Daily,STAMP ... (4 Replies)
Discussion started by: ajayakunuri
4 Replies

3. Filesystems, Disks and Memory

iostat output vs TPC output (array layer)

Hi Guys, I've been having some arguments with my colleagues about one thing. Always my thought was that as as far as disk performance is concern by looking at the output of the iostat command (AIX) you would be able to identify if you have a hot disk and then by moving some files out that disk... (3 Replies)
Discussion started by: arizah
3 Replies

4. Shell Programming and Scripting

howto place in one line output from two functions

Hi I would like to place in one line output from two functions. Both functions return text with print cmd. When I place above code in script it will place them in series. e.g. 1 #/bin/ksh 2 3 function1() 4 { 5 print "My name is" 6 ... (3 Replies)
Discussion started by: presul
3 Replies

5. Shell Programming and Scripting

Enumerate ls -l output

Hi, I'm using normally ls -l to get the content of a directoy. But, it's possible to enumerate the ls output ? (like put the line number at the begining of each line) If it wasn't possible (I don't hope so ...), there's a way to get the line number the line had after doing a grep: ls -l... (8 Replies)
Discussion started by: tecnitek
8 Replies

6. Solaris

6120 Array. Additional physical Disks and ZFS

Hi; I have 4 new disks in a 6120 Array attached to a SUN server running zfs. There are already two virtual disks on the array comprising of 3 disk raid 5 for each Vdisk. I need to add two more disks to each vdisk making each a 5 disk raid 5 Vdisk. If ZFS already has the original... (3 Replies)
Discussion started by: myjess
3 Replies

7. Solaris

adding existing disks to a 3510 array

I would like to extend a logical drive on our 3510. I have four unallocated disks which I would like to use for this purpose. The 3510 supports a Sun Cluster but for now all I wish to see is a "new" disk when I run format. I am a little familiar with the telnet/ssh session on the 3510 but am... (2 Replies)
Discussion started by: malcqv
2 Replies

8. Solaris

New Array of disks

I was just curious if anyone has a good tutorial or some info about how I can create and add an array of disks to solaris 8 (11 Replies)
Discussion started by: BRaider
11 Replies

9. Filesystems, Disks and Memory

how to assign same mount point for file systems mounted on physical disks

We have 6 hard disks attached to the hardware. Of this 2 hard disks are of 9 GB each. Now I want combine both the same in such a way that i see a combined entry in the output of df -k . The steps I follow are 1. Create partition on hard disks (Using format partition) 2. Run newfs -v for... (6 Replies)
Discussion started by: Hitesh Shah
6 Replies

10. Shell Programming and Scripting

How to place the output of two different echo statements on one line

Hello there, I wrote a shell script to modify the code for some of our clients in our client database. Before starting the data modification the program performs a few checks. When a check is being performed, it should be shown on the screen of the user running the program, the result of... (5 Replies)
Discussion started by: JoBa
5 Replies
Login or Register to Ask a Question