之前的帖子使用了针对 Ubuntu Mate 18.04 的过时信息。
根据这篇文章,使用 systemd 在挂起之前和之后运行脚本,我有这个脚本/lib/systemd/system-sleep/
:
#!/bin/bash
#
# located in /lib/systemd/system-sleep/
# Created 4/2/19
exec 2> /tmp/systemd_suspend_test_err.txt
if [ "${1}" = "pre" ]; then
# Do the thing you want before suspend here
echo "we are suspending." > /tmp/systemd_suspend_test.txt
elif [ "${1}" = "post" ]; then
# Do the thing you want after resume here
echo "and we are back from being suspended" >> /tmp/systemd_suspend_test.txt
fi
但这些echo
说法均不起作用。
答案1
我觉得自己有点愚蠢,但我忘了设置执行位。现在,在我使用以下命令后,脚本可以正常工作:
chmod +x