DEV Community

Discussion on: Automating your keyboard's backlit with Bash

Collapse
 
justabaka profile image
Just a baka

You may run it using @reboot in the same crontab or take advantage of your init system (sysvinit / systemd / etc). But you'll now have to calculate the desired led state (on/off) in your run command or script, which can be achieved by simply comparing the current 24-h formatted hour value with 6 and 18.

#!/bin/bash

current_hour=`date +%H`
led_value="led"

if [ $current_hour -ge 6 ] && [ $current_hour -lt 18 ];
then
    led_value="-led"
fi

/path/to/xset $led_value named 'Scroll Lock'

This can be compacted to an one (and ugly) one-liner and put everywhere. A bit more civilized way would be to leave it as a shell script.

# notice the cron.d syntax
@reboot root /path/to/our_super_script.sh
0 6,18 * * * root /path/to/our_super_script.sh