0

I am on a TPLink Router running OpenWRT. When the device starts I want one LED to be on until the system time was updated from the ntp server.

This is my approach:

#!/bin/sh

echo 0 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio0/direction
echo 1 > /sys/class/gpio/gpio0/value

currentDate=$(date +%s)

 while [ $currentDate < 1342016035 ]; do
                echo Time not updated yet
                currentDate=$(date +%s)
done

echo Time updated!

echo 0 > /sys/class/gpio/gpio0/value
echo 0 > /sys/class/gpio/unexport

I get "./timescript.sh: line 11: can't open 1342016035: no such file" when I run it. Do you know why this is happening? Another question is, whether this makes sense at all or is the processor occupied while in the loop and cant update the time?

Thanks in advance!!

Dennis Williamson
  • 346,391
  • 90
  • 374
  • 439
tzippy
  • 6,458
  • 30
  • 82
  • 151

1 Answers1

3

test requires -lt and -gt for arithmetics

#!/bin/sh

echo 0 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio0/direction
echo 1 > /sys/class/gpio/gpio0/value

currentDate=$(date +%s)

while [ $currentDate -lt 1342016035 ]; do
            echo "Time not updated yet"
            currentDate=$(date +%s)
done

echo "Time updated!"

echo 0 > /sys/class/gpio/gpio0/value
echo 0 > /sys/class/gpio/unexport
Harald Brinkhof
  • 4,375
  • 1
  • 22
  • 32