Simpler Navigation for Servers and Operating Systems - Please Update Your Bookmarks
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
If you have bookmarked forums or discussion boards in Servers and Operating Systems, we suggest you check and update them as needed.
Languages and Scripting
cancel
Showing results for 
Search instead for 
Did you mean: 

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

SOLVED
Go to solution
support_billa
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
Dennis Handly
Acclaimed Contributor

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

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

support_billa
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

Dennis Handly
Acclaimed Contributor
Solution

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

The major and minor are encoded in the size field.

support_billa
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

James R. Ferguson
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...

support_billa
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
James R. Ferguson
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...