Page 1 of 2

What is the best way to run a bash script periodically?

Posted: Sun Jul 17, 2016 11:29 am
by smart_lover
I need to run my custom bash script to check if TV uptime is more than X(configurable) then TV reboot itself using 'micom reboot'.
I already know that TV always returns '1970' date! and also I know that crontab is not available on TV.

What is the best way to run a script periodically to check if uptime is more than X hours and after that reboot TV? (I need a way with minimum impact to TV's functionality)

My bad solution is writing a service and use some scheduling method on it and with helps of Telnet and checking TV's uptime, Service can easily send 'micom reboot' to TV. But in this way I have to have an always power on computer beside of my TV!

Re: What is the best way to run a bash script periodically?

Posted: Sun Jul 17, 2016 11:44 am
by sectroyer
smart_lover wrote:I need to run my custom bash script to check if TV uptime is more than X(configurable) then TV reboot itself using 'micom reboot'.
I already know that TV always returns '1970' date! and also I know that crontab is not available on TV.

What is the best way to run a script periodically to check if uptime is more than X hours and after that reboot TV? (I need a way with minimum impact to TV's functionality)

My bad solution is writing a service and use some scheduling method on it and with helps of Telnet and checking TV's uptime, Service can easily send 'micom reboot' to TV. But in this way I have to have an always power on computer beside of my TV!
Use getcurrenttimefromtv and do what you want :)

Re: What is the best way to run a bash script periodically?

Posted: Sun Jul 17, 2016 1:23 pm
by smart_lover
sectroyer wrote:Use getcurrenttimefromtv and do what you want :)
Where can I find this function? It seems In E series there is no such function.
gettime.png
I need it in both E and H series.
Actually I need a way to run my script periodically to check TV uptime( I already knew about getting TV's uptime).
please help me a little more!

Re: What is the best way to run a bash script periodically?

Posted: Sun Jul 17, 2016 3:17 pm
by juusso
Use search...
SpoilerShow
sectroyer wrote:Simple App that just gets Current Time directly from TV (based on hedaks findings)
Sample usage:

Code: Select all

 /getsetcurrenttimefromtv -n exeDSP 
Current Time: 1393671424
Current TimeZone Number: 9
Current TimeZone Offset: 60
The current date/time is: Sat Mar  1 10:57:04 2014
Current Time+Offset: 1393675024
The current date/time+offset is: Sat Mar  1 11:57:04 2014
To set the current time run this:

Code: Select all

/getsetcurrenttimefromtv -n exeDSP -s
EDIT:
New version. Added D/E support.

EDIT2:
Update. Added TimeZone support.

EDIT3:
New version. The app now also sets the time.

EDIT4:
Update. Added "date mode".

EDIT5:
Update. Added set2 option (forces +offset on C).

EDIT6:
Update. Removed set2 option (now app always adds +offset to current time). Add --utc switch.

EDIT7:
Update. Added "date mode" for correct time zone (-U)
If you want to use getsetcurrenttimefromtv instead of default date command add this line to $SYSROOT/etc/rc.sysinit:

Code: Select all

echo "alias date='getsetcurrenttimefromtv -n exeDSP -D'" >> /dtv/.ashrc
Or if you set your timezone correctly use this:

Code: Select all

echo "alias date='getsetcurrenttimefromtv -n exeDSP -U'" >> /dtv/.ashrc

EDIT8: 
Added support for additional display formats (-Y,-M,etc.)


Re: What is the best way to run a bash script periodically?

Posted: Sun Jul 17, 2016 4:17 pm
by smart_lover
juusso wrote:Use search...
I already searched with no success before my post!
I searched 'getcurrenttimefromtv'(as sectroyer said) instead of 'getsetcurrenttimefromtv'
Anyway, Thanks for your help to correct my typo.
Does this lib works in H series?

But my main question is how can I run my script(bash or anything equivalent) periodically in TV.

Re: What is the best way to run a bash script periodically?

Posted: Sun Jul 17, 2016 6:26 pm
by sectroyer
smart_lover wrote: But my main question is how can I run my script(bash or anything equivalent) periodically in TV.

Code: Select all

while
do
   sleep 1
   echo "run your 'script(bash or anything equivalent) periodically in TV.'"; 
done
hope this help :)

Re: What is the best way to run a bash script periodically?

Posted: Sun Jul 17, 2016 6:33 pm
by juusso
smart_lover wrote:Does this lib works in H series?
I guess it should. Try and tell us ;)

Re: What is the best way to run a bash script periodically?

Posted: Mon Jul 18, 2016 9:44 pm
by smart_lover
sectroyer wrote:
smart_lover wrote: But my main question is how can I run my script(bash or anything equivalent) periodically in TV.

Code: Select all

while
do
   sleep 1
   echo "run your 'script(bash or anything equivalent) periodically in TV.'"; 
done
hope this help :)
Of course it helps!

I use below script

Code: Select all

#!/bin/sh

upSeconds="$(cat /proc/uptime | grep -o '^[0-9]\+')"
upMins=$((${upSeconds} / 60))

until [ "${upMins}" -gt "2880" ] ; do
   sleep 30m
   upSeconds="$(cat /proc/uptime | grep -o '^[0-9]\+')"
   upMins=$((${upSeconds} / 60))
done
samyGOrc -p $(pidof exeTV || pidof exeDSP) 152
It works perfectly. But how can I run this script at TV startup? ( I know a little about init.d and I fear to start my script at TV startup for the risk of bootloop)

Is above script a bad script or not? It is important to me that above script do not cause a TV crash at the end of day. I need an optimize script.

F.Y.I: I need some script to power off TV's panel after 48 hours of continues TV power on. Is there any solution available that is more optimize than my solution?

Re: What is the best way to run a bash script periodically?

Posted: Mon Jul 18, 2016 10:50 pm
by sectroyer
Name your script 99_99_myscript.init, then no problems :)

Re: What is the best way to run a bash script periodically?

Posted: Wed Jul 20, 2016 8:03 pm
by smart_lover
sectroyer wrote:Name your script 99_99_myscript.init, then no problems :)
Let assume I copy my script to 'PanelOff' script and put it to ' /mtd_rwcommon/' folder. Is is better to use following code(Run command in background)

Code: Select all

nohup /mtd_rwcommon/PanelOff> /dev/null 2>&1 &
in '99_99_myscript.init' or just copy my script that contains infinitive 'until' condition to 99_99_myscript.init would be ok?

I am thinking if my script contains infinitive 'until' condition then .init script will not finish and it lead TV to not boot properly(prevent progressing other .init files and TV booting process)