A way to see if a PC is a laptop or workstation

Discuss Applications
Post Reply
User avatar
Basher52
guru
guru
Posts: 919
Joined: Wed Oct 22, 2003 5:57 am
Location: .SE

A way to see if a PC is a laptop or workstation

Post by Basher52 » Fri Jun 03, 2011 4:51 am

Is there a "general" way to see if a machine is a laptop or a workstation?
In my case it's all machines from DELL, but if there is a more general way to see this I'd like to know.

I've tried

Code: Select all

cat /proc/cpuinfo
but that doesn't say anything about a "mobile" CPU.
Someone wrote somewhere that you can see if it's docked but I can't be sure that a computer is that, so that is out.

User avatar
Void Main
Site Admin
Site Admin
Posts: 5716
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

Re: A way to see if a PC is a laptop or workstation

Post by Void Main » Fri Jun 03, 2011 8:15 am

I can think of several ways. Laptops would have batteries for instance and battery state would be shown in /proc/acpi/battery/*/state:

Code: Select all

cat /proc/acpi/battery/*/state | grep "present:.*yes"
present:                 yes
There are probably many much better ways of determining this but that's the first thing that popped into my head. There are a lot of other things that could identify the machine as a laptop under /proc/acpi, just dig around.

User avatar
Basher52
guru
guru
Posts: 919
Joined: Wed Oct 22, 2003 5:57 am
Location: .SE

Re: A way to see if a PC is a laptop or workstation

Post by Basher52 » Fri Jun 03, 2011 5:02 pm

Right here on my server I only have

Code: Select all

/proc/acpi/battery/
and no other files/dir's under that.
You sure are smart :) didn't think of the battery thing, no WorkStation use that :)
I'll check that on my laptop at work and see what that says.
Hopefully I can use that for the scripting.

This all has to do with my own "project" of making stuff automatic when (re)loading a PC with an image
and just today, they changed the "data" and want to make a difference between a workstation and a laptop and I just have to fix that so I hopefully can "show off" and get a permanent job there :P

All this stuff has to do with Novell and Zenworks and the way it "places" computers in different "contexts", but that kinda thing is way over my head right now, all I know is that I need to make a bootable
CD/DVD with this script included so you can put the disc in and reboot, then go away and forget it.

User avatar
Basher52
guru
guru
Posts: 919
Joined: Wed Oct 22, 2003 5:57 am
Location: .SE

Re: A way to see if a PC is a laptop or workstation

Post by Basher52 » Thu May 10, 2012 11:51 am

From about a month ago we've starting to get some DELL Latitude 5420's where the script (http://voidmain.is-a-geek.net/forums/vi ... top#p16622) looking to see if it's a laptop or desktop stop working.
I was googling for it and found that from "now" on the

Code: Select all

/proc/acpi/battery/bat0/state 
code won't work (but it seems that some other model still does) if the the architecture is i686 (if I got that thing correctly).
The funny part for me is that I thought that it might have to be with a new kernel version but we still use the same boot cd's I created in November.

From now on I have to use

Code: Select all

/sys/class/power_supply/...
instead but I also found a page saying that this last one won't popup until you try to find the first one and that I saw today.

I was looking for '/sys/class/power_supply/' but no BAT0 was found I tried to list /proc/acpi/battery/bat0/state that wasn't there and then checked '/sys/class/power_supply' again and now BAT0 was found.

What can I do to make the script working for both types of "setups" 'cos I can't figure out a pretty secure solution for this.
This script is later gonna be on an image that we send to DELL for them to put on all new computers.
This is so we don't have to "load" them with the final operating system hence the computers can be sent out to the customers directly.

//B52

User avatar
Basher52
guru
guru
Posts: 919
Joined: Wed Oct 22, 2003 5:57 am
Location: .SE

Re: A way to see if a PC is a laptop or workstation

Post by Basher52 » Wed May 16, 2012 2:14 pm

as the latest news I can find, this is a bug in the late kernel/acpi but from what I've seen don't really know where the "error" is, kernel or acpi.
I've been testing my "theory" I said here in my recent post on my new machine but that won't work now since 'acpid' fail to start correctly...... but still seem to run.
Maybe it's another process, I don't know but my question still stand... how to really do this since this image is supposed to be sent to DELL as a "full proof" image.


help out and don't get me fired :P :P

User avatar
xyle_one
programmer
programmer
Posts: 129
Joined: Mon Jan 13, 2003 1:02 pm
Contact:

Re: A way to see if a PC is a laptop or workstation

Post by xyle_one » Tue May 22, 2012 4:56 pm

What about checking laptop_mode? I googled around a bit and found this snippet:

Code: Select all

cat /proc/sys/vm/laptop_mode
If it is non-zero, then laptop mode is enabled, if it is 0, then it isn't.

edit:
Found this too:
http://man.he.net/man8/laptop-detect.

User avatar
Basher52
guru
guru
Posts: 919
Joined: Wed Oct 22, 2003 5:57 am
Location: .SE

Re: A way to see if a PC is a laptop or workstation

Post by Basher52 » Wed May 23, 2012 2:59 pm

This seem very interesting :)
thx, I'll have a big look on that as soon as I can.
Do you know if this is a "permanent" thing or just a flux that might change in like a year or so?

If this works, you "saved" my life :)
and I'll send ya a toaster :P

User avatar
xyle_one
programmer
programmer
Posts: 129
Joined: Mon Jan 13, 2003 1:02 pm
Contact:

Re: A way to see if a PC is a laptop or workstation

Post by xyle_one » Thu May 24, 2012 12:35 pm

ha, I have no idea how permanent it is. But it has been around for around 6 years though, so I would imagine it will exist for a while longer.

User avatar
Basher52
guru
guru
Posts: 919
Joined: Wed Oct 22, 2003 5:57 am
Location: .SE

Re: A way to see if a PC is a laptop or workstation

Post by Basher52 » Fri May 25, 2012 8:47 am

k, np

it'll work until it won't :P

User avatar
Basher52
guru
guru
Posts: 919
Joined: Wed Oct 22, 2003 5:57 am
Location: .SE

Re: A way to see if a PC is a laptop or workstation

Post by Basher52 » Wed May 30, 2012 2:23 am

cat /proc/sys/vm/laptop_mode don't seem to work either :(
Doing this on my laptop gives me a '0'

:(

User avatar
Basher52
guru
guru
Posts: 919
Joined: Wed Oct 22, 2003 5:57 am
Location: .SE

Re: A way to see if a PC is a laptop or workstation

Post by Basher52 » Wed May 30, 2012 4:18 am

Just check why the first version of this test doesn't work and it seems that it's the 'if test -e' that fails.

On a DELL 6320 it says that -e is an unknown parameter but on all other machines it works,
and this is so weird since it's the same CD I use for them all.
Also checked that the CD only got one version of 'test' so it's the same so I got no clue to why this happens.


UPDATE:

I also the this:

Code: Select all

if [ -f /proc/acpi/battery/*/state ] ; then....
and it too gave me the same error

User avatar
Basher52
guru
guru
Posts: 919
Joined: Wed Oct 22, 2003 5:57 am
Location: .SE

Re: A way to see if a PC is a laptop or workstation

Post by Basher52 » Thu Jun 07, 2012 7:47 am

I finally found the error :)

The 'Too many arguments' I got on the 6320 was because on this model all the BAT-directories was created thus making the test not working.
In BAT1 and BAT2 the state-file had only one line with:

Code: Select all

Present:    No
Now I'm gonna set the test to only BAT0 and the script works :)

btw, can anyone in here tell me where to put BAT1 and/or BAT2 :P

Post Reply