Getting hard drive serial number from USB devices
Paul Sutton
zen14920-1HOZaDBbGgxaa/9Udqfwiw at public.gmane.org
Sat Jan 14 18:58:52 UTC 2006
Cool that works fine on my system, i had to run it as root though,
anyway, I have a routine somewhere that checks to see if you are logged
in as root but that is a bash script, is there anything similar in perl
that can be added to this?
is 755 the correct permissions for this? IIRC the answer is yes. but
anyone got any other suggestions that would be useful.
Paul
Madison Kelly wrote:
> For the record/interest, here is the code that gets the IDE hard
> drive's serial number:
>
> -=-=-=-=-
> #!/usr/bin/perl
>
> use strict;
> use warnings;
> use FileHandle;
>
> my $dev="hda";
>
> my $read_id = new FileHandle;
> if ( $read_id->open("< /proc/ide/$dev/identify") )
> {
> print "This appears to be an IDE disk.\n";
> }
> else
> {
> die "I can't read any devices for: [$dev]\n";
> }
>
> <$read_id>;
> my $sn = substr(<$read_id>,10,29).substr(<$read_id>,0,20);
> $sn=~s/2020//g;
> $sn =~ s/\ //g;
> my $serial;
> $serial.=chr(hex $_) foreach (unpack("a2" x 20,$sn));
> print "The serial number of device: [$dev] is: [$serial].\n";
> $read_id->close;
> exit(0);
> -=-=-=-=-
>
> Sample output:
>
> # ./test.pl
> This appears to be an IDE disk.
> The serial number of device: [hda] is: [3LF00S4C].
> -=-=-=-=-
>
> I am not sure how reliable it is to use '/proc' though... I have a
> vague recollection that '/proc' was being phased out? If possible, I'd
> rather query a device directly.
>
> Madison
>
--
The Toronto Linux Users Group. Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml
More information about the Legacy
mailing list