1

I've been using this suspend hook with Ubuntu & Kubuntu since the days of 12.10, however when I did a clean install of Xubuntu 15.04 yesterday, I noticed it suddenly not working. I've created a file /usr/lib/pm-utils/sleep.d/45fixusbwakeup copied the script into it, and made it executable with sudo chmod +x /usr/lib/pm-utils/sleep.d/45fixusbwakeup as I always did before. I'm not an expert, and this hook has always been working from me, so I don't have a clue what could be wrong now.

What I basically need is that these 3 commands execute every time before computer is going to sleep, or at every startup:

sudo -s
echo USB0 > /proc/acpi/wakeup
echo USB2 > /proc/acpi/wakeup

I would also like to note that when I suspend via terminal command sudo pm-suspend the script works flawlessly, it's only not working via traditional logout--->suspend button in Xubuntu, so I guess this is something Xubuntu-related. I guess it actually suspends via xfce4-session-logout --suspend and that's creating the problem.

Reloader
  • 223

2 Answers2

4

xfce4-session will use systemd-sleep on a systemd system (not pm-suspend). systemd-sleep hooks should be put in /lib/systemd/system-sleep using the following template:

#!/bin/sh
case $1/$2 in
  pre/*)
    echo "Going to $2..."
    ;;
  post/*)
    echo "Waking up from $2..."
    ;;
esac

...and made executable. One other caveat with systemd is that the scripts in this directory are run concurrently, not sequentially based on name (as is the case with pm-utils).

Reloader
  • 223
1

To run the commands on startup

Place the commands (remove sudo -s) into a .sh file and make it executable with chmod +x <filename>.

Create a new bash script containing gksudo -s root <path_to_other_bash_script> and make it executable.

Create a file with a .desktop suffix in the ~/.config/autostart directory - create the folder if you don't have it.

Place the following into the .desktop file:

[Desktop Entry]
Name=name_of_second_bash_script
Exec=path/to/second/script
Type=Application

The commands present in the bash script will be run on startup.

TellMeWhy
  • 17,484
  • sudo -s will ask for the password. – Reloader Jul 01 '15 at 14:31
  • modify it to gksu -s root - it'll prompt you for the sudo password on startup. – TellMeWhy Jul 01 '15 at 14:33
  • gksu -s root obviously don't do as same as sudo -s. After gksu -s root, and entering password, next command, echo USB0 > /proc/acpi/wakeup results in bash: /proc/acpi/wakeup: Permission denied. – Reloader Jul 01 '15 at 14:55
  • Of course, I didn't think of that - see the edit – TellMeWhy Jul 01 '15 at 15:26
  • Now it doesn't prompt me for the password on startup, and of course, does not get the job done. – Reloader Jul 01 '15 at 15:37
  • @Reloader Oops... my mistake :) new edit ;-) If that doesn't work you don't have gksudo installed on your system. – TellMeWhy Jul 01 '15 at 15:49
  • I guess you didn't try it... it simply echos the string USB0 > /proc/acpi/wakeup; echo USB2 > /proc/acpi/wakeup. – user23013 Jul 01 '15 at 15:58
  • I tried, it prompt for a password at the login, but it doesn't change /proc/acpi/wakeup/ settings. Meanwhile, I edited the question, I need a way to change default Xubuntu suspend command to pm-suspend, because script works that way. – Reloader Jul 01 '15 at 17:20
  • @Reloader Been thinking it over and made another edit: "Create a new bash script containing gksudo -s root <path_to_other_bash_script> and make it executable." This isn't related to your last comment btw. – TellMeWhy Jul 01 '15 at 17:38