Ubuntu – Prevent sleep while sharing files over samba
Windows has a little feature that Ubuntu/samba server sadly does not seem to have: On Linux, If another user is accessing files on your samba server, the system will still enter an S3 Sleep / suspend, where as Windows will stay awake until the share is no longer active.
After some research I have developed a script that will prevent Ubuntu from sleeping while sharing files. If your HTPC is accessing videos on your desktop, this can prevent your desktop from sleeping.
These instructions were designed for Ubuntu 10.10 with the GNOME desktop as it relies on a command “gnome-screensaver-command”. If you find another command that can reset the system idle timer, the script could work for you.
To Prevent sleeping while samba is active, create the file ~/.checksmb with the following script: (scroll down for instructions creating file if you don’t know how)
#!/usr/bin/env bash # sleep prevent command - "gnome-screensaver-command --poke" resets idle timer PREVENTSLEEP='gnome-screensaver-command --poke' # gnome-screensaver-command uses X11 which expects this ENV to be set export DISPLAY=:0.0 #### DO NOT EDIT #### smbstatus | grep -q "DENY_WRITE" if [ $? == 0 ]; then $PREVENTSLEEP ; fi
open a terminal (control + alt + T or use menu > Accessories) and type gedit ~/.checksmb and then paste that code into the file, save and close.
Then in the terminal, run chmod +x ~/.checksmb
Nothing should of printed from that.
Then type crontab -e to open the editor for crontab.
If prompted to select an editor, choose what ever number nano is. its the default on Ubuntu 10.10.
Scroll to bottom of file (page down key) and add ON A NEW LINE
* * * * * ~/.checksmb
That line should be all by itself. Now press Control + X, and then press Y to confirm save.
Now, if you haven’t already, you can go configure your PC to go to Sleep after inactivity under System > Preferences > Power Management.
Every 1 minute this script will run and check if anyone is accessing files over Samba (SMB) and it will prevent sleep / suspend.
8 Comments › Leave yours
- Is there a way to automatically prevent sleeping during the day in Linux? - [...] specify Gnome, KDE, or other, but if you’re using Gnome and you extract the meat of this post then ...
Leave a Reply
Log in to Reply