What does Linux know about your hardware?

Code junkies hangout here

Moderators: ChrisThornett, LXF moderators

What does Linux know about your hardware?

Postby Dutch_Master » Thu Jul 24, 2008 2:02 am

On a regular basis (new) members ask help to 'troubleshoot' their system. In most cases it's pretty simple, but sometimes we'd need to know more about your system. I've created a little script you can use to do the 'dirty' work for you. Note that it currently only works on Debian based systems (next to Debian itself also any Ubuntu variant, Xandros and Knoppix) with the lshw package installed. Contributions to make the script distro-independent and a check of wether the required package(s) is/are installed are welcome :)

Code: Select all
#! /bin/bash
#
# script to collect hardware and software data on your system
# you'll need to be root to get proper results
# currently only works in Debian based systems, with the lshw package installed

# what kernel are you running?
echo uname -a: `uname -a` > mysystem.txt
echo ========= >> mysystem.txt
# find out all you want from your hardware with lshw
lshw >> mysystem.txt
echo ========= >> mysystem.txt
chmod 755 mysystem.txt
echo "done! read the file mysystem.txt in the current directory"
echo "use the cat and grep commands to select sections of interest if you're on the commandline"

exit 0
Save the above text in a text file named "mysystem.sh" or click the link ;)
Make it executable with
Code: Select all
chmod+x mysystem.sh
and run it with
Code: Select all
./mysystem.sh
The resulting text file "mysystem.txt" tells you all Linux knows about your hardware.

That simple? Yes, even 1sf (troll) could use it (although as Mandriva user he won't be able to run it, for now ;))

Anyway, this text file can be used to copy the relevant parts from in your reply (or even the original question!)

Frankly, I hope you won't need it, but if you do, let me know if it worked for you (it works on my system (pun intended :P))
Dutch_Master
LXF regular
 
Posts: 2459
Joined: Tue Mar 27, 2007 1:49 am

RE: What does Linux know about your hardware?

Postby nelz » Thu Jul 24, 2008 8:25 am

Change

Code: Select all
echo uname -a: `uname -a` > mysystem.txt

to
Code: Select all
echo uname -a: $(uname -a) >|mysystem.txt


or it will fail if someone has the noclobber option set in their shell, or even

Code: Select all
echo "uname -a:" >|mysystem.txt
uname -a >>mysystem.txt


which saves spawning another shell process.

Note that some distros install lshw into /usr/sbin, which may cause problems if you try to make the script distro-agnostic. Anyway, you should check that it is installed before trying to run it.

Code: Select all
if which lshw &>/dev/null; then
   lshw >> mysystem.txt
else
   echo "You need to install lshw to use this script!
fi


Why do you make the output file executable?
"Insanity: doing the same thing over and over again and expecting different results." (Albert Einstein)
User avatar
nelz
Site admin
 
Posts: 8548
Joined: Mon Apr 04, 2005 11:52 am
Location: Warrington, UK

RE: What does Linux know about your hardware?

Postby ollie » Thu Jul 24, 2008 11:02 am

After installing lshw (and dependencies) the script works fine on my Asus Eee PC running the default Xandros (updated) and my self built Intel Q6600 running Ubuntu 8.04.1. The output to text is well presented and easy to search through.

Great work DM, this should be included on the LXF DVD! :D :!: :idea:
User avatar
ollie
Moderator
 
Posts: 2749
Joined: Mon Jul 25, 2005 11:26 am
Location: Bathurst NSW Australia

RE: What does Linux know about your hardware?

Postby Dutch_Master » Thu Jul 24, 2008 12:02 pm

Nelz, thanks for the suggestions, I've incorporated them in the script. The reason I've put in the chmod line is because the file is created by root and may not be readable as normal user. Changed the permissions to 644, 'cause that does the trick as well :)

Ollie, glad you liked it. Not sure it's mature enough to be on the LXF dvd's though ;)
Dutch_Master
LXF regular
 
Posts: 2459
Joined: Tue Mar 27, 2007 1:49 am

RE: What does Linux know about your hardware?

Postby ollie » Thu Jul 24, 2008 12:48 pm

I'm sure it is!

I'd add:
Code: Select all
echo ========= >> mysystem.txt
echo "System info at:" `date` >> mysystem.txt
echo ========= >> mysystem.txt


at the start of the script just so you can check if the script was run before or after changes have been made.
User avatar
ollie
Moderator
 
Posts: 2749
Joined: Mon Jul 25, 2005 11:26 am
Location: Bathurst NSW Australia

Postby bobthebob1234 » Thu Jul 24, 2008 1:35 pm

erm, nelz

i think your missing an "

if which lshw &>/dev/null; then
lshw >> mysystem.txt
else
echo "You need to install lshw to use this script!
fi

should be
Code: Select all
if which lshw &>/dev/null; then
   lshw >> mysystem.txt
else
   echo "You need to install lshw to use this script!"
fi



I spent ages trying to get the script to work after i added your code!

Good idea though
Last edited by bobthebob1234 on Thu Jul 24, 2008 1:44 pm, edited 1 time in total.
User avatar
bobthebob1234
LXF regular
 
Posts: 1373
Joined: Thu Jan 03, 2008 9:38 pm
Location: A hole in a field

Postby bobthebob1234 » Thu Jul 24, 2008 1:42 pm

'd add:
Code:
echo ========= >> mysystem.txt
echo "System info at:" `date` >> mysystem.txt
echo ========= >> mysystem.txt


at the start of the script just so you can check if the script was run before or after changes have been made.


Prehaps having the file as

mysystem date +%D .txt

might be better?


(PS, i don't know the exact syntax... :roll: )
User avatar
bobthebob1234
LXF regular
 
Posts: 1373
Joined: Thu Jan 03, 2008 9:38 pm
Location: A hole in a field

Postby pwbrum61 » Thu Jul 24, 2008 2:07 pm

For those of you who might dabble with Solaris, similar information to that from lshw can be obtained with

prtconf -v

:)
Where's the Kaboom? There's supposed to be an Earth-shattering kaboom! :D

.
User avatar
pwbrum61
LXF regular
 
Posts: 308
Joined: Fri Sep 29, 2006 9:02 am
Location: Worcestershire

Postby Dutch_Master » Thu Jul 24, 2008 11:00 pm

That's a very reasonable addition Ollie, you're in :) Had to change some bits though ;) Bob, thx for getting the typo, fixed it. Solaris, however tempting and interesting, is a step too far for now pwbrum61, first get some distro-independence on Linux ;) But I'll keep it warm for later use! :)
Dutch_Master
LXF regular
 
Posts: 2459
Joined: Tue Mar 27, 2007 1:49 am

Postby ollie » Thu Jul 24, 2008 11:25 pm

Thanks :D
User avatar
ollie
Moderator
 
Posts: 2749
Joined: Mon Jul 25, 2005 11:26 am
Location: Bathurst NSW Australia

Postby Dutch_Master » Tue Jul 29, 2008 10:39 pm

Quick note to let you know that:
1) althought the script quoted above does work, it's version 0.001 and the link offers version 0.003 for 'download'. That is, the link always has the latest version available.
2) I'm downloading Fedora 9 ATM and will install it in a VirtualBox environment when done. Basic extention for rpm based distro's is therefor in progress. (but not yet available!) Don't hold your breath for it! ;)
Dutch_Master
LXF regular
 
Posts: 2459
Joined: Tue Mar 27, 2007 1:49 am

Postby Dutch_Master » Thu Sep 18, 2008 12:07 am

Update 2:

Getting Fedora to work on a virtual machine turns out to be a PITA. Slow, slugish, not responsive at all. I instantly knew again why I chose Debian in the first place :P Tried OpenSuse too, same results :( Any rpm based distro you guys would recommend that runs acceptable on a virtual machine?
Dutch_Master
LXF regular
 
Posts: 2459
Joined: Tue Mar 27, 2007 1:49 am

Postby ollie » Thu Sep 18, 2008 2:10 am

With current distros you will have problems if they are configured by default to use Compiz, which requires 3D acceleration, which means that openSUSE with KDE4 would definitely have issues. You may also have to give the virtual machine more RAM if it is running very slowly. That's the big advantage of having a 64-bit OS as the base OS, you can install and use plenty of RAM :D
User avatar
ollie
Moderator
 
Posts: 2749
Joined: Mon Jul 25, 2005 11:26 am
Location: Bathurst NSW Australia

Postby Dutch_Master » Thu Sep 18, 2008 2:21 am

Thanks for the warning Ollie, but as Gnomy I wouldn't choose KDE anyway ;)

The host has 2 GB RAM onboard, and 512 MB for a guest, and runs 64 bit Debian. Should suffice, shouldn't it? Frankly, any (modern) Linux distro that needs more then 512 MB RAM would be just as bad as M$ Vi$ta :evil:

Hmmm, would CentOS do, RH-based as it is? I'll see if I can get some .iso tomorrow ;)
Dutch_Master
LXF regular
 
Posts: 2459
Joined: Tue Mar 27, 2007 1:49 am

Postby ollie » Thu Sep 18, 2008 6:25 am

Dutch_Master wrote:Thanks for the warning Ollie, but as Gnomy I wouldn't choose KDE anyway ;)

The host has 2 GB RAM onboard, and 512 MB for a guest, and runs 64 bit Debian. Should suffice, shouldn't it? Frankly, any (modern) Linux distro that needs more then 512 MB RAM would be just as bad as M$ Vi$ta :evil:

Hmmm, would CentOS do, RH-based as it is? I'll see if I can get some .iso tomorrow ;)


:lol: Gnomey still has Compiz.

I think CentOS would be closer to RHEL than Fedora.

I'm flat out with Software Freedom Day at the moment, but I'll see if I can do some testing on different distros after I have a week off.

8) No computers, no mobile phone reception - just fishing, sailing and pulling kids around behind my speedboat at Windamere Dam. :D
User avatar
ollie
Moderator
 
Posts: 2749
Joined: Mon Jul 25, 2005 11:26 am
Location: Bathurst NSW Australia

Next

Return to Programming

Who is online

Users browsing this forum: No registered users and 1 guest