BladeSystem Forums have moved here
To make BladeSystem information easier to find, we have moved the BladeSystem forums here, to Servers and Operating Systems.
Languages and Scripting
Showing results for 
Search instead for 
Do you mean 

how can i get major and minor number (perl, shell script)

SOLVED
Go to Solution
Valued Contributor

how can i get major and minor number (perl, shell script)

how can i get with standard modules the "major nr" of unix group file ?

at Modul "File::stat" i didn't find anything:

i only found following modul :

http://search.cpan.org/~pirzyk/Unix-Mknod-0.04/lib...

but in my perl env it doesn't exist :

i want of example file /dev/volumegr/group following outputs :
ll /dev/volumegr/group
crw-r--r-- 1 root sys 64 0x040000 Oct 8 2007 /dev/volumegr/group

major: 0x040000 , minor: 64

 

or the other way with shell script is to parse "ll -d /dev/volumegr/group" ?

 

regards

 

7 REPLIES
Acclaimed Contributor

Re: how can I get major and minor number (perl, shell script)

[ Edited ]

tusc shows that ll(1) is just calling lstat(2).

Valued Contributor

Re: how can i get major and minor number (perl, shell script)

hello,

 

@ tusc shows that ll(1) is just calling lstat(2).

 

i search now for "lstat"  and i found "lstat" use field nr. 6

 

lstat / stat function

 

i tried with a little script , but no success

 

regards

Acclaimed Contributor

Re: how can I get major and minor number (perl, shell script)

The major and minor are encoded in the size field.

Valued Contributor

Re: how can I get major and minor number (perl, shell script)

hello,

i got it :

 

printf " File major is %d ,\n minor is 0x%06.6x\n", ($dev >> 24) & 0xff, $rdev & 0xffffff;

 

regards

Acclaimed Contributor

Re: how can I get major and minor number (perl, shell script)

Hi:

While you seem to have found a solution, remember, CPAN is your friend.  To guarantee portability, you could fetch and install 'File::Stat::Bits':

 

http://search.cpan.org/~fedorov/File-Stat-Bits-1.01/

 

Regards!

 

...JRF...

Valued Contributor

Re: how can I get major and minor number (perl, shell script)

hello,

 

what do yo recommend ?

 

my solution or


http://search.cpan.org/~fedorov/File-Stat-Bits-1.01/ 

?

a little question : with what "key" to you search at CPAN ? with "major nr" you get nothing and only "major" you get to much information ...

Highlighted
Acclaimed Contributor

Re: how can I get major and minor number (perl, shell script)


support_billa wrote:

what do yo recommend ?

my solution or
http://search.cpan.org/~fedorov/File-Stat-Bits-1.01/ 

?

a little question : with what "key" to you search at CPAN ? with "major nr" you get nothing and only "major" you get to much information ...


For portability, I would use the Perl module. 

 

As for how I found the module, the stat() system call is the key, so I searched for modules with "stat".

 

Regards!

 

...JRF...