how to execute a command after resume from suspend?
I've got a script that is executed in order to have suspending/resuming working in my laptop. Then I have another series of xinput
,xkbset
and xmodmap
commands that are executed when I initiate a session to have two-finger scrolling and keyboard shortcuts set up. When I resume from suspend, two-finger scrolling and my keyboard shortcuts won't work. I need to manually execute the commands in the second file again. How can I add those to the suspend/resume script to have this done automatically? See below:
suspend/resume script
/etc/pm/sleep.d/20_custom-ehci_hcd
#!/bin/sh
#inspired by http://art.ubuntuforums.org/showpost.php?p=9744970&postcount=19
#...and http://thecodecentral.com/2011/01/18/fix-ubuntu-10-10-suspendhibernate-not-working-bug
# tidied by tqzzaa :)
VERSION=1.1
DEV_LIST=/tmp/usb-dev-list
DRIVERS_DIR=/sys/bus/pci/drivers
DRIVERS="ehci xhci" # ehci_hcd, xhci_hcd
HEX="[[:xdigit:]]"
MAX_BIND_ATTEMPTS=2
BIND_WAIT=0.1
unbindDev() {
echo -n > $DEV_LIST 2>/dev/null
for driver in $DRIVERS; do
DDIR=$DRIVERS_DIR/${driver}_hcd
for dev in `ls $DDIR 2>/dev/null | egrep "^$HEX+:$HEX+:$HEX"`; do
echo -n "$dev" > $DDIR/unbind
echo "$driver $dev" >> $DEV_LIST
done
done
}
bindDev() {
if [ -s $DEV_LIST ]; then
while read driver dev; do
DDIR=$DRIVERS_DIR/${driver}_hcd
while [ $((MAX_BIND_ATTEMPTS)) -gt 0 ]; do
echo -n "$dev" > $DDIR/bind
if [ ! -L "$DDIR/$dev" ]; then
sleep $BIND_WAIT
else
break
fi
MAX_BIND_ATTEMPTS=$((MAX_BIND_ATTEMPTS-1))
done
done < $DEV_LIST
fi
rm $DEV_LIST 2>/dev/null
}
case "$1" in
hibernate|suspend) unbindDev;;
resume|thaw) bindDev;;
esac
touchpad two-finger scrolling and keyboard shortcuts script
xinput set-int-prop "SynPS/2 Synaptics TouchPad" "Two-Finger Scrolling" 8 1
xinput set-int-prop "SynPS/2 Synaptics TouchPad" "Synaptics Two-Finger Scrolling" 8 1 1
xinput set-int-prop "SynPS/2 Synaptics TouchPad" "Synaptics Two-Finger Pressure" 32 10
xinput set-int-prop "SynPS/2 Synaptics TouchPad" "Synaptics Two-Finger Width" 32 8
setxkbmap -layout gb
xkbset m
xkbset exp =m
xmodmap -e "keycode 135 = Pointer_Button2"
scripts suspend-resume session
add a comment |
I've got a script that is executed in order to have suspending/resuming working in my laptop. Then I have another series of xinput
,xkbset
and xmodmap
commands that are executed when I initiate a session to have two-finger scrolling and keyboard shortcuts set up. When I resume from suspend, two-finger scrolling and my keyboard shortcuts won't work. I need to manually execute the commands in the second file again. How can I add those to the suspend/resume script to have this done automatically? See below:
suspend/resume script
/etc/pm/sleep.d/20_custom-ehci_hcd
#!/bin/sh
#inspired by http://art.ubuntuforums.org/showpost.php?p=9744970&postcount=19
#...and http://thecodecentral.com/2011/01/18/fix-ubuntu-10-10-suspendhibernate-not-working-bug
# tidied by tqzzaa :)
VERSION=1.1
DEV_LIST=/tmp/usb-dev-list
DRIVERS_DIR=/sys/bus/pci/drivers
DRIVERS="ehci xhci" # ehci_hcd, xhci_hcd
HEX="[[:xdigit:]]"
MAX_BIND_ATTEMPTS=2
BIND_WAIT=0.1
unbindDev() {
echo -n > $DEV_LIST 2>/dev/null
for driver in $DRIVERS; do
DDIR=$DRIVERS_DIR/${driver}_hcd
for dev in `ls $DDIR 2>/dev/null | egrep "^$HEX+:$HEX+:$HEX"`; do
echo -n "$dev" > $DDIR/unbind
echo "$driver $dev" >> $DEV_LIST
done
done
}
bindDev() {
if [ -s $DEV_LIST ]; then
while read driver dev; do
DDIR=$DRIVERS_DIR/${driver}_hcd
while [ $((MAX_BIND_ATTEMPTS)) -gt 0 ]; do
echo -n "$dev" > $DDIR/bind
if [ ! -L "$DDIR/$dev" ]; then
sleep $BIND_WAIT
else
break
fi
MAX_BIND_ATTEMPTS=$((MAX_BIND_ATTEMPTS-1))
done
done < $DEV_LIST
fi
rm $DEV_LIST 2>/dev/null
}
case "$1" in
hibernate|suspend) unbindDev;;
resume|thaw) bindDev;;
esac
touchpad two-finger scrolling and keyboard shortcuts script
xinput set-int-prop "SynPS/2 Synaptics TouchPad" "Two-Finger Scrolling" 8 1
xinput set-int-prop "SynPS/2 Synaptics TouchPad" "Synaptics Two-Finger Scrolling" 8 1 1
xinput set-int-prop "SynPS/2 Synaptics TouchPad" "Synaptics Two-Finger Pressure" 32 10
xinput set-int-prop "SynPS/2 Synaptics TouchPad" "Synaptics Two-Finger Width" 32 8
setxkbmap -layout gb
xkbset m
xkbset exp =m
xmodmap -e "keycode 135 = Pointer_Button2"
scripts suspend-resume session
This seems to be a duplicate of askubuntu.com/questions/226278/run-script-on-wakeup/483714. See also my comment at askubuntu.com/a/483714/170127.
– jamadagni
Jun 15 '14 at 16:40
add a comment |
I've got a script that is executed in order to have suspending/resuming working in my laptop. Then I have another series of xinput
,xkbset
and xmodmap
commands that are executed when I initiate a session to have two-finger scrolling and keyboard shortcuts set up. When I resume from suspend, two-finger scrolling and my keyboard shortcuts won't work. I need to manually execute the commands in the second file again. How can I add those to the suspend/resume script to have this done automatically? See below:
suspend/resume script
/etc/pm/sleep.d/20_custom-ehci_hcd
#!/bin/sh
#inspired by http://art.ubuntuforums.org/showpost.php?p=9744970&postcount=19
#...and http://thecodecentral.com/2011/01/18/fix-ubuntu-10-10-suspendhibernate-not-working-bug
# tidied by tqzzaa :)
VERSION=1.1
DEV_LIST=/tmp/usb-dev-list
DRIVERS_DIR=/sys/bus/pci/drivers
DRIVERS="ehci xhci" # ehci_hcd, xhci_hcd
HEX="[[:xdigit:]]"
MAX_BIND_ATTEMPTS=2
BIND_WAIT=0.1
unbindDev() {
echo -n > $DEV_LIST 2>/dev/null
for driver in $DRIVERS; do
DDIR=$DRIVERS_DIR/${driver}_hcd
for dev in `ls $DDIR 2>/dev/null | egrep "^$HEX+:$HEX+:$HEX"`; do
echo -n "$dev" > $DDIR/unbind
echo "$driver $dev" >> $DEV_LIST
done
done
}
bindDev() {
if [ -s $DEV_LIST ]; then
while read driver dev; do
DDIR=$DRIVERS_DIR/${driver}_hcd
while [ $((MAX_BIND_ATTEMPTS)) -gt 0 ]; do
echo -n "$dev" > $DDIR/bind
if [ ! -L "$DDIR/$dev" ]; then
sleep $BIND_WAIT
else
break
fi
MAX_BIND_ATTEMPTS=$((MAX_BIND_ATTEMPTS-1))
done
done < $DEV_LIST
fi
rm $DEV_LIST 2>/dev/null
}
case "$1" in
hibernate|suspend) unbindDev;;
resume|thaw) bindDev;;
esac
touchpad two-finger scrolling and keyboard shortcuts script
xinput set-int-prop "SynPS/2 Synaptics TouchPad" "Two-Finger Scrolling" 8 1
xinput set-int-prop "SynPS/2 Synaptics TouchPad" "Synaptics Two-Finger Scrolling" 8 1 1
xinput set-int-prop "SynPS/2 Synaptics TouchPad" "Synaptics Two-Finger Pressure" 32 10
xinput set-int-prop "SynPS/2 Synaptics TouchPad" "Synaptics Two-Finger Width" 32 8
setxkbmap -layout gb
xkbset m
xkbset exp =m
xmodmap -e "keycode 135 = Pointer_Button2"
scripts suspend-resume session
I've got a script that is executed in order to have suspending/resuming working in my laptop. Then I have another series of xinput
,xkbset
and xmodmap
commands that are executed when I initiate a session to have two-finger scrolling and keyboard shortcuts set up. When I resume from suspend, two-finger scrolling and my keyboard shortcuts won't work. I need to manually execute the commands in the second file again. How can I add those to the suspend/resume script to have this done automatically? See below:
suspend/resume script
/etc/pm/sleep.d/20_custom-ehci_hcd
#!/bin/sh
#inspired by http://art.ubuntuforums.org/showpost.php?p=9744970&postcount=19
#...and http://thecodecentral.com/2011/01/18/fix-ubuntu-10-10-suspendhibernate-not-working-bug
# tidied by tqzzaa :)
VERSION=1.1
DEV_LIST=/tmp/usb-dev-list
DRIVERS_DIR=/sys/bus/pci/drivers
DRIVERS="ehci xhci" # ehci_hcd, xhci_hcd
HEX="[[:xdigit:]]"
MAX_BIND_ATTEMPTS=2
BIND_WAIT=0.1
unbindDev() {
echo -n > $DEV_LIST 2>/dev/null
for driver in $DRIVERS; do
DDIR=$DRIVERS_DIR/${driver}_hcd
for dev in `ls $DDIR 2>/dev/null | egrep "^$HEX+:$HEX+:$HEX"`; do
echo -n "$dev" > $DDIR/unbind
echo "$driver $dev" >> $DEV_LIST
done
done
}
bindDev() {
if [ -s $DEV_LIST ]; then
while read driver dev; do
DDIR=$DRIVERS_DIR/${driver}_hcd
while [ $((MAX_BIND_ATTEMPTS)) -gt 0 ]; do
echo -n "$dev" > $DDIR/bind
if [ ! -L "$DDIR/$dev" ]; then
sleep $BIND_WAIT
else
break
fi
MAX_BIND_ATTEMPTS=$((MAX_BIND_ATTEMPTS-1))
done
done < $DEV_LIST
fi
rm $DEV_LIST 2>/dev/null
}
case "$1" in
hibernate|suspend) unbindDev;;
resume|thaw) bindDev;;
esac
touchpad two-finger scrolling and keyboard shortcuts script
xinput set-int-prop "SynPS/2 Synaptics TouchPad" "Two-Finger Scrolling" 8 1
xinput set-int-prop "SynPS/2 Synaptics TouchPad" "Synaptics Two-Finger Scrolling" 8 1 1
xinput set-int-prop "SynPS/2 Synaptics TouchPad" "Synaptics Two-Finger Pressure" 32 10
xinput set-int-prop "SynPS/2 Synaptics TouchPad" "Synaptics Two-Finger Width" 32 8
setxkbmap -layout gb
xkbset m
xkbset exp =m
xmodmap -e "keycode 135 = Pointer_Button2"
scripts suspend-resume session
scripts suspend-resume session
edited Jan 3 '12 at 10:48
719016
asked Jan 2 '12 at 14:32
719016719016
1,4202467108
1,4202467108
This seems to be a duplicate of askubuntu.com/questions/226278/run-script-on-wakeup/483714. See also my comment at askubuntu.com/a/483714/170127.
– jamadagni
Jun 15 '14 at 16:40
add a comment |
This seems to be a duplicate of askubuntu.com/questions/226278/run-script-on-wakeup/483714. See also my comment at askubuntu.com/a/483714/170127.
– jamadagni
Jun 15 '14 at 16:40
This seems to be a duplicate of askubuntu.com/questions/226278/run-script-on-wakeup/483714. See also my comment at askubuntu.com/a/483714/170127.
– jamadagni
Jun 15 '14 at 16:40
This seems to be a duplicate of askubuntu.com/questions/226278/run-script-on-wakeup/483714. See also my comment at askubuntu.com/a/483714/170127.
– jamadagni
Jun 15 '14 at 16:40
add a comment |
3 Answers
3
active
oldest
votes
You can place your scripts in the /etc/pm/sleep.d
directory to have them run after suspend. You will need to add a conditional to make your script run only during resume and not during the suspend process as well. For example, your touchpad script would look like:
case "${1}" in
resume|thaw)
DISPLAY=:0.0 ; export DISPLAY
xinput set-int-prop "SynPS/2 Synaptics TouchPad" "Two-Finger Scrolling" 8 1
xinput set-int-prop "SynPS/2 Synaptics TouchPad" "Synaptics Two-Finger Scrolling" 8 1 1
xinput set-int-prop "SynPS/2 Synaptics TouchPad" "Synaptics Two-Finger Pressure" 32 10
xinput set-int-prop "SynPS/2 Synaptics TouchPad" "Synaptics Two-Finger Width" 32 8
setxkbmap -layout gb
xkbset m
xkbset exp =m
su $USER -c "sleep 3; /usr/bin/xmodmap -e "keycode 135 = Pointer_Button2"" &
;;
esac
Be sure your script is marked globally executable and change $USER to the corresponding username.
You can find more detailed information in the pm-suspend manpage (man pm-suspend
) or by looking at the documentation in /usr/share/doc/pm-utils
(particularly /usr/share/doc/pm-utils/HOWTO.hooks.gz
).
2
It can be called whatever you like. It's a good idea to start it with a number between 00-49, per the pm-suspend manpage: "00 - 49 User and most package supplied hooks. If a hook assumes that all of the usual services and userspace infrastructure is still running, it should be here."
– fader
Jan 3 '12 at 13:28
3
Another (now deleted) answer had this: 'please note the following bug report: launchpad.net/ubuntu/+source/pm-utils/+bug/1455097 after upgrading to vivid scripts need to be put into/lib/systemd/system-sleep/
'
– Wilf
Aug 15 '15 at 9:43
8
On Ubuntu 15.10, the script has to be in/lib/systemd/system-sleep/
instead of/etc/pm/sleep
.
– Marc Belmont
Jan 25 '16 at 14:00
6
On Ubuntu 16.04 the arguments given to the script arepre
before entering suspend andpost
after resume instead ofsuspend
andresume
– Germar
Jul 22 '16 at 0:34
3
Tried the last two comments here on yakkety (16.10), and it didn't work. How to troubleshoot?
– Gringo Suave
Oct 18 '16 at 18:53
|
show 3 more comments
On Ubuntu 16.04 I had to create service this way:
create file
sudo gedit /etc/systemd/system/somename.service
put inside
[Unit]
Description=Some description
Before=sleep.target
StopWhenUnneeded=yes
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStop=-/path/to/your/script.sh
[Install]
WantedBy=sleep.target
enable service
sudo systemctl enable somename
(optional) if not working after resume from suspend > check for errors with
journalctl -u somename.service
This also seems to work on Ubuntu 18.04, thanks!
– kelunik
Jun 18 '18 at 7:02
Why does Ubuntu leave /etc/pm/sleep.d lying around if it doesn't use it? It is confusing and misleading.
– Jonathan Neufeld
Sep 23 '18 at 3:42
add a comment |
Open this file:
sudo vim /lib/systemd/system-sleep/hdparm
Contents:
#!/bin/sh
case $1 in
post)
/usr/lib/pm-utils/power.d/95hdparm-apm resume
## Paste your command to run your script
;; esac
Your command will execute with admin privileges.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f92218%2fhow-to-execute-a-command-after-resume-from-suspend%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can place your scripts in the /etc/pm/sleep.d
directory to have them run after suspend. You will need to add a conditional to make your script run only during resume and not during the suspend process as well. For example, your touchpad script would look like:
case "${1}" in
resume|thaw)
DISPLAY=:0.0 ; export DISPLAY
xinput set-int-prop "SynPS/2 Synaptics TouchPad" "Two-Finger Scrolling" 8 1
xinput set-int-prop "SynPS/2 Synaptics TouchPad" "Synaptics Two-Finger Scrolling" 8 1 1
xinput set-int-prop "SynPS/2 Synaptics TouchPad" "Synaptics Two-Finger Pressure" 32 10
xinput set-int-prop "SynPS/2 Synaptics TouchPad" "Synaptics Two-Finger Width" 32 8
setxkbmap -layout gb
xkbset m
xkbset exp =m
su $USER -c "sleep 3; /usr/bin/xmodmap -e "keycode 135 = Pointer_Button2"" &
;;
esac
Be sure your script is marked globally executable and change $USER to the corresponding username.
You can find more detailed information in the pm-suspend manpage (man pm-suspend
) or by looking at the documentation in /usr/share/doc/pm-utils
(particularly /usr/share/doc/pm-utils/HOWTO.hooks.gz
).
2
It can be called whatever you like. It's a good idea to start it with a number between 00-49, per the pm-suspend manpage: "00 - 49 User and most package supplied hooks. If a hook assumes that all of the usual services and userspace infrastructure is still running, it should be here."
– fader
Jan 3 '12 at 13:28
3
Another (now deleted) answer had this: 'please note the following bug report: launchpad.net/ubuntu/+source/pm-utils/+bug/1455097 after upgrading to vivid scripts need to be put into/lib/systemd/system-sleep/
'
– Wilf
Aug 15 '15 at 9:43
8
On Ubuntu 15.10, the script has to be in/lib/systemd/system-sleep/
instead of/etc/pm/sleep
.
– Marc Belmont
Jan 25 '16 at 14:00
6
On Ubuntu 16.04 the arguments given to the script arepre
before entering suspend andpost
after resume instead ofsuspend
andresume
– Germar
Jul 22 '16 at 0:34
3
Tried the last two comments here on yakkety (16.10), and it didn't work. How to troubleshoot?
– Gringo Suave
Oct 18 '16 at 18:53
|
show 3 more comments
You can place your scripts in the /etc/pm/sleep.d
directory to have them run after suspend. You will need to add a conditional to make your script run only during resume and not during the suspend process as well. For example, your touchpad script would look like:
case "${1}" in
resume|thaw)
DISPLAY=:0.0 ; export DISPLAY
xinput set-int-prop "SynPS/2 Synaptics TouchPad" "Two-Finger Scrolling" 8 1
xinput set-int-prop "SynPS/2 Synaptics TouchPad" "Synaptics Two-Finger Scrolling" 8 1 1
xinput set-int-prop "SynPS/2 Synaptics TouchPad" "Synaptics Two-Finger Pressure" 32 10
xinput set-int-prop "SynPS/2 Synaptics TouchPad" "Synaptics Two-Finger Width" 32 8
setxkbmap -layout gb
xkbset m
xkbset exp =m
su $USER -c "sleep 3; /usr/bin/xmodmap -e "keycode 135 = Pointer_Button2"" &
;;
esac
Be sure your script is marked globally executable and change $USER to the corresponding username.
You can find more detailed information in the pm-suspend manpage (man pm-suspend
) or by looking at the documentation in /usr/share/doc/pm-utils
(particularly /usr/share/doc/pm-utils/HOWTO.hooks.gz
).
2
It can be called whatever you like. It's a good idea to start it with a number between 00-49, per the pm-suspend manpage: "00 - 49 User and most package supplied hooks. If a hook assumes that all of the usual services and userspace infrastructure is still running, it should be here."
– fader
Jan 3 '12 at 13:28
3
Another (now deleted) answer had this: 'please note the following bug report: launchpad.net/ubuntu/+source/pm-utils/+bug/1455097 after upgrading to vivid scripts need to be put into/lib/systemd/system-sleep/
'
– Wilf
Aug 15 '15 at 9:43
8
On Ubuntu 15.10, the script has to be in/lib/systemd/system-sleep/
instead of/etc/pm/sleep
.
– Marc Belmont
Jan 25 '16 at 14:00
6
On Ubuntu 16.04 the arguments given to the script arepre
before entering suspend andpost
after resume instead ofsuspend
andresume
– Germar
Jul 22 '16 at 0:34
3
Tried the last two comments here on yakkety (16.10), and it didn't work. How to troubleshoot?
– Gringo Suave
Oct 18 '16 at 18:53
|
show 3 more comments
You can place your scripts in the /etc/pm/sleep.d
directory to have them run after suspend. You will need to add a conditional to make your script run only during resume and not during the suspend process as well. For example, your touchpad script would look like:
case "${1}" in
resume|thaw)
DISPLAY=:0.0 ; export DISPLAY
xinput set-int-prop "SynPS/2 Synaptics TouchPad" "Two-Finger Scrolling" 8 1
xinput set-int-prop "SynPS/2 Synaptics TouchPad" "Synaptics Two-Finger Scrolling" 8 1 1
xinput set-int-prop "SynPS/2 Synaptics TouchPad" "Synaptics Two-Finger Pressure" 32 10
xinput set-int-prop "SynPS/2 Synaptics TouchPad" "Synaptics Two-Finger Width" 32 8
setxkbmap -layout gb
xkbset m
xkbset exp =m
su $USER -c "sleep 3; /usr/bin/xmodmap -e "keycode 135 = Pointer_Button2"" &
;;
esac
Be sure your script is marked globally executable and change $USER to the corresponding username.
You can find more detailed information in the pm-suspend manpage (man pm-suspend
) or by looking at the documentation in /usr/share/doc/pm-utils
(particularly /usr/share/doc/pm-utils/HOWTO.hooks.gz
).
You can place your scripts in the /etc/pm/sleep.d
directory to have them run after suspend. You will need to add a conditional to make your script run only during resume and not during the suspend process as well. For example, your touchpad script would look like:
case "${1}" in
resume|thaw)
DISPLAY=:0.0 ; export DISPLAY
xinput set-int-prop "SynPS/2 Synaptics TouchPad" "Two-Finger Scrolling" 8 1
xinput set-int-prop "SynPS/2 Synaptics TouchPad" "Synaptics Two-Finger Scrolling" 8 1 1
xinput set-int-prop "SynPS/2 Synaptics TouchPad" "Synaptics Two-Finger Pressure" 32 10
xinput set-int-prop "SynPS/2 Synaptics TouchPad" "Synaptics Two-Finger Width" 32 8
setxkbmap -layout gb
xkbset m
xkbset exp =m
su $USER -c "sleep 3; /usr/bin/xmodmap -e "keycode 135 = Pointer_Button2"" &
;;
esac
Be sure your script is marked globally executable and change $USER to the corresponding username.
You can find more detailed information in the pm-suspend manpage (man pm-suspend
) or by looking at the documentation in /usr/share/doc/pm-utils
(particularly /usr/share/doc/pm-utils/HOWTO.hooks.gz
).
edited Nov 27 '13 at 12:55
Community♦
1
1
answered Jan 2 '12 at 15:14
faderfader
4,16111715
4,16111715
2
It can be called whatever you like. It's a good idea to start it with a number between 00-49, per the pm-suspend manpage: "00 - 49 User and most package supplied hooks. If a hook assumes that all of the usual services and userspace infrastructure is still running, it should be here."
– fader
Jan 3 '12 at 13:28
3
Another (now deleted) answer had this: 'please note the following bug report: launchpad.net/ubuntu/+source/pm-utils/+bug/1455097 after upgrading to vivid scripts need to be put into/lib/systemd/system-sleep/
'
– Wilf
Aug 15 '15 at 9:43
8
On Ubuntu 15.10, the script has to be in/lib/systemd/system-sleep/
instead of/etc/pm/sleep
.
– Marc Belmont
Jan 25 '16 at 14:00
6
On Ubuntu 16.04 the arguments given to the script arepre
before entering suspend andpost
after resume instead ofsuspend
andresume
– Germar
Jul 22 '16 at 0:34
3
Tried the last two comments here on yakkety (16.10), and it didn't work. How to troubleshoot?
– Gringo Suave
Oct 18 '16 at 18:53
|
show 3 more comments
2
It can be called whatever you like. It's a good idea to start it with a number between 00-49, per the pm-suspend manpage: "00 - 49 User and most package supplied hooks. If a hook assumes that all of the usual services and userspace infrastructure is still running, it should be here."
– fader
Jan 3 '12 at 13:28
3
Another (now deleted) answer had this: 'please note the following bug report: launchpad.net/ubuntu/+source/pm-utils/+bug/1455097 after upgrading to vivid scripts need to be put into/lib/systemd/system-sleep/
'
– Wilf
Aug 15 '15 at 9:43
8
On Ubuntu 15.10, the script has to be in/lib/systemd/system-sleep/
instead of/etc/pm/sleep
.
– Marc Belmont
Jan 25 '16 at 14:00
6
On Ubuntu 16.04 the arguments given to the script arepre
before entering suspend andpost
after resume instead ofsuspend
andresume
– Germar
Jul 22 '16 at 0:34
3
Tried the last two comments here on yakkety (16.10), and it didn't work. How to troubleshoot?
– Gringo Suave
Oct 18 '16 at 18:53
2
2
It can be called whatever you like. It's a good idea to start it with a number between 00-49, per the pm-suspend manpage: "00 - 49 User and most package supplied hooks. If a hook assumes that all of the usual services and userspace infrastructure is still running, it should be here."
– fader
Jan 3 '12 at 13:28
It can be called whatever you like. It's a good idea to start it with a number between 00-49, per the pm-suspend manpage: "00 - 49 User and most package supplied hooks. If a hook assumes that all of the usual services and userspace infrastructure is still running, it should be here."
– fader
Jan 3 '12 at 13:28
3
3
Another (now deleted) answer had this: 'please note the following bug report: launchpad.net/ubuntu/+source/pm-utils/+bug/1455097 after upgrading to vivid scripts need to be put into
/lib/systemd/system-sleep/
'– Wilf
Aug 15 '15 at 9:43
Another (now deleted) answer had this: 'please note the following bug report: launchpad.net/ubuntu/+source/pm-utils/+bug/1455097 after upgrading to vivid scripts need to be put into
/lib/systemd/system-sleep/
'– Wilf
Aug 15 '15 at 9:43
8
8
On Ubuntu 15.10, the script has to be in
/lib/systemd/system-sleep/
instead of /etc/pm/sleep
.– Marc Belmont
Jan 25 '16 at 14:00
On Ubuntu 15.10, the script has to be in
/lib/systemd/system-sleep/
instead of /etc/pm/sleep
.– Marc Belmont
Jan 25 '16 at 14:00
6
6
On Ubuntu 16.04 the arguments given to the script are
pre
before entering suspend and post
after resume instead of suspend
and resume
– Germar
Jul 22 '16 at 0:34
On Ubuntu 16.04 the arguments given to the script are
pre
before entering suspend and post
after resume instead of suspend
and resume
– Germar
Jul 22 '16 at 0:34
3
3
Tried the last two comments here on yakkety (16.10), and it didn't work. How to troubleshoot?
– Gringo Suave
Oct 18 '16 at 18:53
Tried the last two comments here on yakkety (16.10), and it didn't work. How to troubleshoot?
– Gringo Suave
Oct 18 '16 at 18:53
|
show 3 more comments
On Ubuntu 16.04 I had to create service this way:
create file
sudo gedit /etc/systemd/system/somename.service
put inside
[Unit]
Description=Some description
Before=sleep.target
StopWhenUnneeded=yes
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStop=-/path/to/your/script.sh
[Install]
WantedBy=sleep.target
enable service
sudo systemctl enable somename
(optional) if not working after resume from suspend > check for errors with
journalctl -u somename.service
This also seems to work on Ubuntu 18.04, thanks!
– kelunik
Jun 18 '18 at 7:02
Why does Ubuntu leave /etc/pm/sleep.d lying around if it doesn't use it? It is confusing and misleading.
– Jonathan Neufeld
Sep 23 '18 at 3:42
add a comment |
On Ubuntu 16.04 I had to create service this way:
create file
sudo gedit /etc/systemd/system/somename.service
put inside
[Unit]
Description=Some description
Before=sleep.target
StopWhenUnneeded=yes
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStop=-/path/to/your/script.sh
[Install]
WantedBy=sleep.target
enable service
sudo systemctl enable somename
(optional) if not working after resume from suspend > check for errors with
journalctl -u somename.service
This also seems to work on Ubuntu 18.04, thanks!
– kelunik
Jun 18 '18 at 7:02
Why does Ubuntu leave /etc/pm/sleep.d lying around if it doesn't use it? It is confusing and misleading.
– Jonathan Neufeld
Sep 23 '18 at 3:42
add a comment |
On Ubuntu 16.04 I had to create service this way:
create file
sudo gedit /etc/systemd/system/somename.service
put inside
[Unit]
Description=Some description
Before=sleep.target
StopWhenUnneeded=yes
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStop=-/path/to/your/script.sh
[Install]
WantedBy=sleep.target
enable service
sudo systemctl enable somename
(optional) if not working after resume from suspend > check for errors with
journalctl -u somename.service
On Ubuntu 16.04 I had to create service this way:
create file
sudo gedit /etc/systemd/system/somename.service
put inside
[Unit]
Description=Some description
Before=sleep.target
StopWhenUnneeded=yes
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStop=-/path/to/your/script.sh
[Install]
WantedBy=sleep.target
enable service
sudo systemctl enable somename
(optional) if not working after resume from suspend > check for errors with
journalctl -u somename.service
answered May 28 '18 at 21:41
janotjanot
76111028
76111028
This also seems to work on Ubuntu 18.04, thanks!
– kelunik
Jun 18 '18 at 7:02
Why does Ubuntu leave /etc/pm/sleep.d lying around if it doesn't use it? It is confusing and misleading.
– Jonathan Neufeld
Sep 23 '18 at 3:42
add a comment |
This also seems to work on Ubuntu 18.04, thanks!
– kelunik
Jun 18 '18 at 7:02
Why does Ubuntu leave /etc/pm/sleep.d lying around if it doesn't use it? It is confusing and misleading.
– Jonathan Neufeld
Sep 23 '18 at 3:42
This also seems to work on Ubuntu 18.04, thanks!
– kelunik
Jun 18 '18 at 7:02
This also seems to work on Ubuntu 18.04, thanks!
– kelunik
Jun 18 '18 at 7:02
Why does Ubuntu leave /etc/pm/sleep.d lying around if it doesn't use it? It is confusing and misleading.
– Jonathan Neufeld
Sep 23 '18 at 3:42
Why does Ubuntu leave /etc/pm/sleep.d lying around if it doesn't use it? It is confusing and misleading.
– Jonathan Neufeld
Sep 23 '18 at 3:42
add a comment |
Open this file:
sudo vim /lib/systemd/system-sleep/hdparm
Contents:
#!/bin/sh
case $1 in
post)
/usr/lib/pm-utils/power.d/95hdparm-apm resume
## Paste your command to run your script
;; esac
Your command will execute with admin privileges.
add a comment |
Open this file:
sudo vim /lib/systemd/system-sleep/hdparm
Contents:
#!/bin/sh
case $1 in
post)
/usr/lib/pm-utils/power.d/95hdparm-apm resume
## Paste your command to run your script
;; esac
Your command will execute with admin privileges.
add a comment |
Open this file:
sudo vim /lib/systemd/system-sleep/hdparm
Contents:
#!/bin/sh
case $1 in
post)
/usr/lib/pm-utils/power.d/95hdparm-apm resume
## Paste your command to run your script
;; esac
Your command will execute with admin privileges.
Open this file:
sudo vim /lib/systemd/system-sleep/hdparm
Contents:
#!/bin/sh
case $1 in
post)
/usr/lib/pm-utils/power.d/95hdparm-apm resume
## Paste your command to run your script
;; esac
Your command will execute with admin privileges.
answered Jan 21 at 16:52
Abhishek SinghAbhishek Singh
112
112
add a comment |
add a comment |
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f92218%2fhow-to-execute-a-command-after-resume-from-suspend%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
This seems to be a duplicate of askubuntu.com/questions/226278/run-script-on-wakeup/483714. See also my comment at askubuntu.com/a/483714/170127.
– jamadagni
Jun 15 '14 at 16:40