Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Extracting System Info

by Anonymous Monk
on Jul 23, 2001 at 15:52 UTC ( [id://98976]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I wish to search /proc/pci for some info. Copy the data and write it to a new location. Specifically it involves searching /proc/pci for a particular device ID and assigning the devices IO addresses to a set of variables and then writing these variables out to another file (or calling a program and passing the values as arguments. Do you have some skeleton code which would do something similar that I can tinker with... Cheers

Replies are listed 'Best First'.
Re: Extracting System Info
by MZSanford (Curate) on Jul 23, 2001 at 16:22 UTC
    Just so i can get a better idea, what kind of machine is this ?

    Well, found some info on the /proc/pci (i had not worked with it before), and whipped up a quick starter ... use at your own risk, your milage may vary ...blah blah blah. Hope it helps.
    #!/usr/bin/perl -w use strict; my @devices; $/ = "\n "; while (my $lines = <DATA>) { my %hash; if ($lines =~ m/Bus (\d+), device (\d+), function (\d+):/) { $hash{bus} = $1; $hash{device} = $2; $hash{function} = $3; } ## parse other lines ... push @devices,\%hash; } # use @devices # /proc/pci from # http://web.gnu.walfield.org/mail-archive/linux-kernel/1999-October/0 +315.html __END__ PCI devices found: Bus 0, device 0, function 0: Host bridge: Intel Unknown device (rev 3). Vendor id=8086. Device id=7190. Medium devsel. Master Capable. Latency=64. Prefetchable 32 bit memory at 0xe6000000 [0xe6000008]. Bus 0, device 1, function 0: PCI bridge: Intel Unknown device (rev 3). Vendor id=8086. Device id=7191. Medium devsel. Master Capable. Latency=64. Min Gnt=136. Bus 0, device 7, function 0: ISA bridge: Intel 82371AB PIIX4 ISA (rev 2). Medium devsel. Fast back-to-back capable. Master Capable. No bur +sts. Bus 0, device 7, function 1: IDE interface: Intel 82371AB PIIX4 IDE (rev 1). Medium devsel. Fast back-to-back capable. Master Capable. Latenc +y=64. I/O at 0xf000 [0xf001]. Bus 0, device 7, function 2: USB Controller: Intel 82371AB PIIX4 USB (rev 1). Medium devsel. Fast back-to-back capable. Master Capable. Latenc +y=64. I/O at 0xe000 [0xe001]. Bus 0, device 7, function 3: Bridge: Intel 82371AB PIIX4 ACPI (rev 2). Medium devsel. Fast back-to-back capable. Bus 0, device 9, function 0: Ethernet controller: Realtek 8029 (rev 0). Medium devsel. IRQ 12. I/O at 0xe400 [0xe401]. Bus 0, device 11, function 0: Non-VGA device: NCR 53c810 (rev 1). Medium devsel. IRQ 10. Master Capable. Latency=64. I/O at 0xe800 [0xe801]. Non-prefetchable 32 bit memory at 0xe7000000 [0xe7000000]. Bus 1, device 0, function 0: VGA compatible controller: Matrox Unknown device (rev 3). Vendor id=102b. Device id=525. Medium devsel. Fast back-to-back capable. IRQ 11. Master Capable +. Latency=64. Min Gnt=16.Max Lat=32. Prefetchable 32 bit memory at 0xe4000000 [0xe4000008]. Non-prefetchable 32 bit memory at 0xe0000000 [0xe0000000]. Non-prefetchable 32 bit memory at 0xe1000000 [0xe1000000].

    remeber the immortal word's of Socrates who said, "I drank what ?"
      In this case, you treat /proc/pci per line. Perhaps you would like to read the file by records, like:

      # example of a full record Bus 0, device 0, function 0: Host bridge: Intel Unknown device (rev 3). Vendor id=8086. Device id=7190. Medium devsel. Master Capable. Latency=64. Prefetchable 32 bit memory at 0xe6000000 [0xe6000008].

      If so, you only need to make a slight modification to MZSanford code:

      use strict; my @devices; undef $/; foreach (split /\n\s\s\b/, <DATA>) { # you now have the whole record in $_ # do with it as you please } <snip>

      - Good luck

      The machine is a standard Intel Pentium PC. The section of /proc/pci I am interested in, looks like this:-
      Bus 0, device 15, function 0 Unknown class: Unknown vendor Unknown device (rev 1). Vendor id=135a. Device id=61. Medium devsel. Fast back-to-back capable. IRQ 9 Non-prefetchable 32 bit memory at 0x412000000 I/O at 0x2080 I/O at 0x2400 I/O at 0x2410 Blah.. Blah..
      I am interested in seeking out devices with this vendor and device id and then getting just the I/O entires (just 2nd and 3rd though, not interested in the first. I tried the posted example but got:
      Name "main::DATA" used only once: possible type at line 6 readline() on closed filehandle main::DATA at line 6..
      Ahhh...
        The stuff that he put after the __END__ line gets read into the filehandle called DATA. So, what you want to do is open up /proc/pci yourself (since you won't have the data embedded in your script.)

        Try putting this line before the while loop:
        open(DATA, '/proc/pci') or die "Can't open /proc/pci: $!";

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://98976]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2024-03-28 15:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found