Hacking LMDE

Write tutorials and howtos in here
More tutorials here http://community.linuxmint.com/tutorial/welcome
Forum rules
Do not start a support topic here please, Before you post please read this

Re: Hacking LMDE

Postby terdon on Tue Jul 19, 2011 9:34 am

HTD wrote:Would you like to wake up your pc from sleep with keyboard or mouse? It's easy:

Code: Select all
((echo '#!/bin/sh' && sed -rn 's/^.*(USB[0-9E]+|EUSB).*$/echo \1 > \/proc\/acpi\/wakeup/pg' /proc/acpi/wakeup) | sudo tee /etc/pm/sleep.d/05_usb && sudo chmod +x /etc/pm/sleep.d/05_usb)



Hi, this command won't work on my laptop. If I read it correctly, the sed command will substitute lines matching USB with the "echo 1 ..." command. I have no lines containing that pattern on my /proc/acpi/wakeup. I guess this is because I am running LMDE on a laptop. I do have a keyboard connected but, believe it or not, it is an old PS2 one. So, the question is, which line in my /proc/acpi/wakeup file refers to my laptop keyboard, which refers to the external one and how can I get the above command to work?

I guess the idea here is to create a bash script at /etc/pm/sleep.d/05_usb which will echo "1" into /proc/acpi/wakeup. Is that correct? Or did you mean "$1" for capturing the sed command's output? Or am I missing the point entirely?

/proc/acpi/wakeup:
Code: Select all
Device   S-state     Status   Sysfs node
AGP     S4   *disabled  pci:0000:00:01.0
P0P1     S4   *disabled  pci:0000:00:1e.0
HDEF     S4   *disabled  pci:0000:00:1b.0
RP01     S4   *disabled  pci:0000:00:1c.0
PXSX     S4   *disabled 
RP02     S4   *disabled  pci:0000:00:1c.1
PXSX     S4   *disabled  pci:0000:03:00.0
RP03     S4   *disabled  pci:0000:00:1c.2
PXSX     S4   *disabled  pci:0000:04:00.0
RP04     S4   *disabled  pci:0000:00:1c.3
PXSX     S4   *disabled 
RP05     S4   *disabled 
PXSX     S4   *disabled 
RP07     S4   *disabled 
PXSX     S4   *disabled 
RP08     S4   *disabled 
PXSX     S4   *disabled 
GLAN     S4   *enabled   pci:0000:00:19.0
PEG3     S4   *disabled 
PEG4     S4   *disabled 
PEG5     S4   *disabled 
PEG6     S4   *disabled 
EHC2     S3   *disabled  pci:0000:00:1a.0
EHCI     S3   *disabled  pci:0000:00:1d.0
LID     S3   *enabled   
PBTN     S3   *enabled   





PS. What is this file anyway? What does this mean?
Code: Select all
$ file /proc/acpi/wakeup
/proc/acpi/wakeup: empty

Using more or cat to see the file shows me the contents perfectly. Copying it to my $HOME results in:
Code: Select all
$ file wakeup
wakeup: ASCII text

:?
User avatar
terdon
Level 4
Level 4
 
Posts: 276
Joined: Tue Jan 13, 2009 2:52 pm
Location: Marseille

Linux Mint is funded by ads and donations.
 

Re: Hacking LMDE

Postby HTD on Sun Aug 21, 2011 10:00 am

This is not a normal file. It's procfs thingie which behaves a little as regular file, but it is not. It's a simple way for reading and writing to system components like drivers, daemons and such.
/proc/acpi/wakeup "file" contains list of device names which will be used for waking up the pc.

You can write to this file to test the changes immediately, but real thing is done there:
/etc/pm/sleep.d/05_usb - this is the real file, which contains device names which will be added to /proc/acpi/wakeup each time system goes to sleep.

How do I got the list of device names? Just cat /proc/acpi/wakeup . The rest of the magic line do all the voodoo removing all the text we don't need from this output - and puts it into /etc/pm/sleep.d/05_usb file. The file needs to have chmod +x. That's all. You can change the filter pattern in magic line to include other devices like this:

Code: Select all
((echo '#!/bin/sh' && sed -rn 's/^.*(PS2K|USB[0-9E]+|EUSB).*$/echo \1 > \/proc\/acpi\/wakeup/pg' /proc/acpi/wakeup) | sudo tee /etc/pm/sleep.d/05_usb && sudo chmod +x /etc/pm/sleep.d/05_usb)


...to include PS2 keyboard. When I figured it out I was quite new to linux shell magic and used "sed" and "tee" for the first time in my life :) So it took me some time to read the manuals, but it was fun :) I would never try it, but as a web programmer I use regular expressions everyday, so I thought - damn it - I don't know nothing about linux shell but I know regexes so I HAVE to make it! :)

And well, this is the way to go - instead of telling you to do a lot of things to change the system sleep settings (which would be hard to tell and hard to follow) I just wrote it as a single line which does everything. Finds device names, filters them, writes them to a file, and changes the file permission :). Oh, the "tee" is because "sudo echo" doesn't work (long story) :)
HTD
Level 1
Level 1
 
Posts: 46
Joined: Sun May 22, 2011 7:31 pm

Previous

Return to Tutorials / Howtos

Who is online

Users browsing this forum: No registered users and 3 guests