Monday, September 5, 2016

How to Prevent Sleep When Remote Connection is On

This post is based on here. To prevent your system from going to sleep while ssh connection is on, follow the steps below:

Create /etc/pm/sleep.d/05_ssh_keepawake file
$ sudo vim /etc/pm/sleep.d/05_ssh_keepawake

Copy the following content to the file
#check for SSH sessions, and prevent suspending:
if [ `who | grep -cv "(:"` -gt 0 ]; then
        echo "SSH session(s) are on. Not suspending."
        exit 1;

Make it executable
$ sudo chmod +x /etc/pm/sleep.d/05_ssh_keepawake

Make sure to reboot your system to take effect!

No comments:

Post a Comment