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...
I'm trying that but it doesn't quite work. I don't have 'gnome-screensaver-command --poke' on Linux Mint. So I tried to modify it a little but I'm quite a noob for this:
#!/usr/bin/env bash
sleep prevent command - "gnome-screensaver-command --poke" resets idle timer
PREVENTSLEEP= xdotool key a
gnome-screensaver-command uses X11 which expects this ENV to be set
export DISPLAY=:0.0
DO NOT EDIT
smbstatus | grep -q "DENY_NONE" if [ $? == 0 ]; then $PREVENTSLEEP ; fi
This doesn't work as expected. No matter what smbstatus is it always runs xdotool command. – Sinisa – 2019-11-07T09:34:21.597