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

This is general talk area for things that NOT RELATED WITH TV! Instead, about internal works like web site, forum, wiki, or talking, etc...

smart_lover
SamyGO Project Donor
Posts: 158
Joined: Sun May 03, 2015 6:11 am

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

Post by smart_lover » Sun Jul 17, 2016 11:29 am

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!

sectroyer
Official SamyGO Developer
Posts: 5630
Joined: Wed May 04, 2011 5:10 pm

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

Post by sectroyer » Sun Jul 17, 2016 11:44 am

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 :)
I do NOT support "latest fw" at ALL. If you have one you should block updates on router and wait for it to STOP being "latest":)
If you want me to help you please paste FULL log(s) to "spoiler"/"code" bbcodes or provide link(s) to pasted file(s) on http://ctrlv.it/ Otherwise "NO HELP"!!!
If you want root DISABLE internet access to your device!!!!
DO NOT EVER INSTALL FIRMWARE UPGRADE !!!!

smart_lover
SamyGO Project Donor
Posts: 158
Joined: Sun May 03, 2015 6:11 am

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

Post by smart_lover » Sun Jul 17, 2016 1:23 pm

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!
You do not have the required permissions to view the files attached to this post.

User avatar
juusso
SamyGO Moderator
Posts: 9665
Joined: Sun Mar 07, 2010 6:20 pm

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

Post by juusso » Sun Jul 17, 2016 3:17 pm

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.)

LE40B653T5W,UE40D6750
Have questions? Read SamyGO Wiki, Search on forum first!
FFB (v0.8), FFB for CI+ . Get root on: C series, D series, E series, F series, H series, exeDSP/exeTV patches[C/D/E/F/H]

DO NOT EVER INSTALL FIRMWARE UPGRADE

smart_lover
SamyGO Project Donor
Posts: 158
Joined: Sun May 03, 2015 6:11 am

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

Post by smart_lover » Sun Jul 17, 2016 4:17 pm

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.

sectroyer
Official SamyGO Developer
Posts: 5630
Joined: Wed May 04, 2011 5:10 pm

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

Post by sectroyer » Sun Jul 17, 2016 6:26 pm

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 :)
I do NOT support "latest fw" at ALL. If you have one you should block updates on router and wait for it to STOP being "latest":)
If you want me to help you please paste FULL log(s) to "spoiler"/"code" bbcodes or provide link(s) to pasted file(s) on http://ctrlv.it/ Otherwise "NO HELP"!!!
If you want root DISABLE internet access to your device!!!!
DO NOT EVER INSTALL FIRMWARE UPGRADE !!!!

User avatar
juusso
SamyGO Moderator
Posts: 9665
Joined: Sun Mar 07, 2010 6:20 pm

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

Post by juusso » Sun Jul 17, 2016 6:33 pm

smart_lover wrote:Does this lib works in H series?
I guess it should. Try and tell us ;)
LE40B653T5W,UE40D6750
Have questions? Read SamyGO Wiki, Search on forum first!
FFB (v0.8), FFB for CI+ . Get root on: C series, D series, E series, F series, H series, exeDSP/exeTV patches[C/D/E/F/H]

DO NOT EVER INSTALL FIRMWARE UPGRADE

smart_lover
SamyGO Project Donor
Posts: 158
Joined: Sun May 03, 2015 6:11 am

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

Post by smart_lover » Mon Jul 18, 2016 9:44 pm

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?

sectroyer
Official SamyGO Developer
Posts: 5630
Joined: Wed May 04, 2011 5:10 pm

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

Post by sectroyer » Mon Jul 18, 2016 10:50 pm

Name your script 99_99_myscript.init, then no problems :)
I do NOT support "latest fw" at ALL. If you have one you should block updates on router and wait for it to STOP being "latest":)
If you want me to help you please paste FULL log(s) to "spoiler"/"code" bbcodes or provide link(s) to pasted file(s) on http://ctrlv.it/ Otherwise "NO HELP"!!!
If you want root DISABLE internet access to your device!!!!
DO NOT EVER INSTALL FIRMWARE UPGRADE !!!!

smart_lover
SamyGO Project Donor
Posts: 158
Joined: Sun May 03, 2015 6:11 am

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

Post by smart_lover » Wed Jul 20, 2016 8:03 pm

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)

Post Reply

Return to “General”