#!/usr/bin/env bash
set -e
while true; do
sleep 20m
xscreensaver-command -activate
sleep 20s
xscreensaver-command -deactivate
done
This presumes that xscreensaver is configured to have a delay before it is locked (and thus requiring a password to unlock - as would happen if we used `xscreensaver-command -lock`).
I accidentally did something similar quite a few years ago when I stupidly set up a grep to run updatedb every two hours. There was several months lag as well between when I did that and my computer started locking up every two hours for a few minutes. And embarrassingly, it took me a week or two to put it together.