How to prevent Linux Mint going to sleep while Samba sharing is active?
Caffeine is a utility available in the package manager that serves a similar function as the scripts. It periodically injects meaningless keyboard activity so the system doesn't appear as idle. Caffeine sticks an icon in the system tray that you can toggle on and off, which is convenient. The publisher's description refers to it working when in full-screen mode. When I last used it, I don't think it required full-screen mode. But worst case, make the application full-screen in that workspace.
I did it! I'll explain how, maybe it will help others.
Install xdotool
sudo apt install xdotool
Then, make a script in /usr/local/bin/
sudo xed /usr/local/bin/checksmb.sh
Copy this to xed:
#!/bin/bash
export DISPLAY=:0
export XAUTHORITY=/home/sinisab89/.Xauthority
if [ `sudo smbstatus | grep DENY | wc -l` != 0 ]
then
xdotool key F9
exit 0
fi
Save file.
DISPLAY and XAUTHORITY is needed for CRON to function properly. smbstatus only runs with sudo. I chose F9 key, maybe there are better options. Script reads smbstatus and if there are more than 0 "DENY" entries in the report (active connections in Samba) simulates F9 key press which resets system idle timer and prevents suspend. If there are 0 "DENY" entries script does nothing.
Make checksmb.sh executable
sudo chmod +x /usr/local/bin/checksmb.sh
Now set up CRON to execute script every x minutes. I chose 20 minutes.
sudo crontab -e
Scroll to the bottom and add
*/20 * * * * /usr/local/bin/checksmb.sh >> /home/YOUR USERNAME/cron.log 2>&1
/home/YOUR USERNAME/cron.log 2>&1 makes a cron.log file in your home folder. You can use it for troubleshooting if the script is not executed properly.
With this command you can see if CRON is executing script at given time
less /var/log/syslog | grep checksmb
This is not the most elegant solution but it works. If someone knows how, for example, video players prevent system from sleeping it would be nice to modify this script so it doesn't use xdotool. There has to be some system suspend inhibitor but I just couldn't find anything online.
I think Caffeine requires user input and doesn't run automatically. Sry I'm replying as this but it doesn't allow me to comment...