how can i get major and minor number (perl, shell script) (1027 Views)
Reply
Valued Contributor
support_billa
Posts: 192
Registered: ‎06-27-2011
Message 1 of 8 (1,027 Views)
Accepted Solution

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

 



Please use plain text.
Acclaimed Contributor
Dennis Handly
Posts: 24,971
Registered: ‎03-06-2006
Message 2 of 8 (1,023 Views)

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

[ Edited ]

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

Please use plain text.
Valued Contributor
support_billa
Posts: 192
Registered: ‎06-27-2011
Message 3 of 8 (1,017 Views)

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

Please use plain text.
Acclaimed Contributor
Dennis Handly
Posts: 24,971
Registered: ‎03-06-2006
Message 4 of 8 (1,013 Views)

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

The major and minor are encoded in the size field.

Please use plain text.
Valued Contributor
support_billa
Posts: 192
Registered: ‎06-27-2011
Message 5 of 8 (997 Views)

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

Please use plain text.
Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 6 of 8 (990 Views)

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...

Please use plain text.
Valued Contributor
support_billa
Posts: 192
Registered: ‎06-27-2011
Message 7 of 8 (985 Views)

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 ...

Please use plain text.
Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 8 of 8 (982 Views)

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...

Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation