DEV Community

has12zen
has12zen

Posted on

Using Cron keep your eyes in check

basic syntax for cron

a typical cron job looks like this

# m h  dom mon dow   command
  * *   *   *   *   /usr/bin/sh ls
Enter fullscreen mode Exit fullscreen mode
  • stand for wildcard this is not a cron tutorial this is just how i use it.

eyes.sh script

the bash script looks like

#!/bin/sh
export DISPLAY=:0
notify-send "EYES CHECK" "Look away for 15 seconds"
Enter fullscreen mode Exit fullscreen mode

without line no 2 it wont work as it sets the display for notify-send. I am using notify-send as my notification daemon.

make sure that your display is :0
you can do this with

echo $DISPLAY
Enter fullscreen mode Exit fullscreen mode

setting up crontab

first you will need to make sure cron is running you can do this by:

systemctl status cronie
Enter fullscreen mode Exit fullscreen mode

p.s. this is specific to arch based system.

once cron is running you can create/edit cron job with crontab -e

then paste the code present below into the window.

*/15 * * * * /usr/bin/sh  /home/elnovo/.noti/eyes.sh
Enter fullscreen mode Exit fullscreen mode

it runs every 15 min and eyes.sh is the bash script we discussed above. save it.
you can find the cron jobs currently present by crontab -l

sources

notify-send doesn't work from crontab

Discussion (1)

Collapse
bartjaskulski profile image
Bartek Jaskulski

Actually, I've written similar code to get along with my eyes, but... it didn't work and I've forgot about it.

Thanks to you, my eyes will rest sometimes 🤣