Last active
December 23, 2024 03:31
-
-
Save zhanglongqi/de6e41bce762d4810914ef8035c92bae to your computer and use it in GitHub Desktop.
Prevent Linux from going to suspend/sleep when ssh connections are on.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# Put this file to /etc/pm/sleep.d/ | |
# chmod +x /etc/pm/sleep.d/99_ssh_keep_awake.sh | |
# | |
# | |
# Thanks to https://askubuntu.com/questions/521620/prevent-machine-from-sleeping-when-ssh-connections-are-on | |
# | |
ip=`w -h | awk '{print $1,$2,$3}' | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'` | |
if [ -z $ip ]; then | |
exit 0 | |
else | |
echo User is still logged from $ip | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks. I have updated it and tested on both of ubuntu 24.04 and 22.04 😄