0

I've created a bash script to allow my keyboard light to turn on at a certain time. I have however not been able to get it running. I have verified the 'light' command and it does work. I've also included echo statements to check if conditions are met but it seems they are skipped all together.

I do know the script is running successfully because i have plotted the output 'test' to a file and that command is written...

Does anyone have an idea what I am doing wrong ?

sorry for the noob question.....

#!/bin/bash
currenttime=$(date +%H:%M)
echo test
if [[ "$currenttime" > "17:00" ]]; then
    if [[ "$currenttime" < "18:00" ]]; then
        light -Srs "sysfs/leds/chromeos::kbd_backlight" 25
        echo 1
    fi
fi

if [[ "$currenttime" > "18:00" ]]; then
    if [[ "$currenttime" < "19:00" ]]; then
        light -Srs "sysfs/leds/chromeos::kbd_backlight" 50
        echo 2
    fi
fi

if [[ "$currenttime" > "19:00" ]]; then
    if  [[ "$currenttime" < "20:00" ]]; then
        light -Srs "sysfs/leds/chromeos::kbd_backlight" 75
        echo 3
    fi
fi

if [[ "$currenttime" > "20:00" ]]; then
    if [[ "$currenttime" < "06:00" ]]; then
        light -Srs "sysfs/leds/chromeos::kbd_backlight" 100
        echo 4
    fi
fi

if [[ "$currenttime" < "07:00" ]]; then
    if [[ "$currenttime" > "06:00" ]]; then
        light -Srs "sysfs/leds/chromeos::kbd_backlight" 50
        echo 5
    fi
fi

if [[ "$currenttime" > "7:00" ]]; then
    if [[ "$currenttime" < "17:00" ]]; then
        light -Srs "sysfs/leds/chromeos::kbd_backlight" 0
        echo 6
    fi
fi

1 Answer 1

1

You're not testing against the value in $currentime but against a str with the value $currentime. You need to remove the quotes around "$currenttime"

Like so:

if [[ $currenttime > "17:00" ]]; then

But it may be waaaay simpler to run the commands in a cronjob. I dont know how you start this script, but if you do it with cronjob and execute every minute then every minute the light program receives a command to adjust the value. I would make more sense to execute the command only on the exact set time you would want to

0 18 * * * light -Srs "sysfs/leds/chromeos::kbd_backlight" 25 >/dev/null 2>&1

0 19 * * * light -Srs "sysfs/leds/chromeos::kbd_backlight" 50 >/dev/null 2>&1

0 20 * * * light -Srs "sysfs/leds/chromeos::kbd_backlight" 100 >/dev/null 2>&1

0 6 * * * light -Srs "sysfs/leds/chromeos::kbd_backlight" 50 >/dev/null 2>&1

0 7 * * * light -Srs "sysfs/leds/chromeos::kbd_backlight" 0 >/dev/null 2>&1

edit:

or run the script every minute and increase the light value by (max_light_val / minutes_till_next_setting). That can be fun :)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .