Tutorial: Scheduled tasks in CoreELEC

This is strange. Do you create your scripts on windows? Can you upload the same script with the “wget” that doesn’t work so I have your unmodified one?

Also the output of:

which wget

For editing scripts I use Notepad ++ for Windows and nano for Linux.

Now the script without $ () works fine but I will continue using $ () because it never failed me. I do not know how to give an explanation, perhaps the epg download file of the website failed when I used the scrip without $ ().

Thanks for your comments

CoreELEC: ~ / .config / scripts # which wget
/ usr / bin / wget
CoreELEC: ~ / .config / scripts #

I get 400 Bad Request when script is DOS formatted.

1 Like

Alright. I never wanted you to not use them. If you feel comfortable use them I was just wondering if there is a bug.
And it’s probably like vpeter said if you have DOS format for scripts the newline character is wrong and only $() helps to avoid this.

1 Like

Thanks for finding out where the problem was.

3 Likes

@cubimol

Excellent guide which I saw just after I posted the problems below in General tab (now deleted for duplication.)

  1. I went into CE Settings and enabled crontab.
    Did #systemctl restart cron and also #systemctl status cron, and # crontab -l (returns nothing.)

So cron seems active…

Then #crontab -e to write a cronjob but get Abort menu via WinSCP login.

So what’s the problem?

  1. How can I install anacrontab to perform jobs that are not missed?

My reference:

https://www.thegeekstuff.com/2011/05/anacron-examples/

Btw, I don’t plan to use any shell script; just a single command line which should be allowed, e.g.

"/etc/anacrontab "?

30 15 stop.kodi systemctl disable kodi.service
START_HOURS_RANGE = 3-22
RANDOM_DELAY = 45

I want my Kodi to be switched off after a month or so on an x96mini box ( 30 days, with 15 min delay after boot.)
If there is an equivalent in crontab I would appreciate it, in case anacrontab cannot be installed !

No anacrontab.

Try to use putty for ssh conection and execute crontab -e.

@vpeter

Thanks, PuTTY did open the crontab.

Now, can you tell me if the command #systemctl disable service.kodi is correct?

Tried from PuTTY. This isn’t working: no effect !
I want to experiment with shutting down Kodi via SSH. I am assuming this will still keep the Linux part running?

Commands are stop and start.

systemctl stop kodi
systemctl start kodi

Oh thanks.
But why doesn’t the above command work, which I found from online at the Arch Linux wiki?

No idea :innocent:

What do you want to achieve? Stop kodi permanently? Then use paramater mask to disable service and unmask to enable back.

Yes.

I would like to stop Kodi after some specified time period, even when I have rebooted the tv box in between. Think they call it a persistent command.

It’ll be nice to have kodi working again too, on demand.

The problem with the systemctl stop kodi command is that kodi is back after reboot.

How to do it?
Sorry I am a Linux noob. What is masking here?

You would need some scripting to achieve this what you want. Cron doesn’t support such functionality.

And why do you need to stop kodi?

Maybe you like my automatic daily restart using cron, maybe this solves some of your doubts, on Mondays and Fridays a full backup runs:

file /storage/.config/scripts/crontab.conf:

20 7 * * Mon /storage/.config/scripts/backup-and-reboot.sh
20 7 * * Tue systemctl reboot
20 7 * * Wed systemctl reboot
20 7 * * Thu systemctl reboot
20 7 * * Fri /storage/.config/scripts/backup-and-reboot.sh
20 7 * * Sat systemctl reboot
20 7 * * Sun systemctl reboot

file /storage/.config/scripts/backup-and-reboot.sh:

#!/bin/sh
# stop main services
systemctl stop kodi
# systemctl stop service.softcam.oscam
# systemctl stop service.tvheadend42
systemctl stop service.tvheadend43
# systemctl stop entware
# save logs for entware servers
mv /opt/var/log/messages /opt/var/log/messages.old
mv /opt/var/log/zerotier-one.log /opt/var/log/zerotier-one.log.old
# full backup
mv /media/EXT-HDD/Backups/full-backup.tar /media/EXT-HDD/Backups/full-backup.old.tar
tar cvf  /media/EXT-HDD/Backups/full-backup.tar /storage/.kodi /storage/.cache /storage/.config /storage/.opt
systemctl reboot

All of this is launched from /storage/.config/autostart.sh with the command:
crontab /storage/.config/scripts/crontab.conf

You can use commas in crontab timers:
20 7 * * 1,5 /storage/.config/scripts/backup-and-reboot.sh
20 7 * * 2,3,4,6,7 systemctl reboot

1 Like

Is there anyway I can bind a script to run with a keyboard press (F1-F12, for instance)?
I want to reboot from nand, to boot to android and it’s a fairly simple command, just need help tying it to a keyboard press.
Thx.

You don’t need 3 commands for this particular case of epg updating. The same result could be reached with just one:

wget -q -O - http://url_of_your_guide/guide.xml.gz | gunzip > /storage/path_to_your_guide_file/guide.xml

And it could be placed directly to crontab. No additional directories and scripts needed.

Hello:

I wanted to ask a “parallel question”

When I create a .sh file like:
“test.sh” with this inside:

#!/bin/sh
echo “Hello world!”

in /storage/downloads

and try to execute it (chmod +x, etc.):

CoreELEC:~/downloads # ./test.sh
sh: ./test.sh: not found
CoreELEC:~/downloads #

But THE SAME FILE, with sh, is executed perfectly:
CoreELEC:~/downloads # sh test.sh
Hello world!
CoreELEC:~/downloads #

And, when I “remove” the part:

#!/bin/sh

and I leave alone the part:

echo “Hello world!”

in the file “test.sh”, then:
CoreELEC:~/downloads # ./test.sh
Hello world!
CoreELEC:~/downloads #

So, for any reason, the part:

#!/bin/sh

makes the test.sh file fail to execute using: ./test.sh

CoreELEC:~/downloads # which sh
/opt/bin/sh
CoreELEC:~/downloads # which bash
/opt/bin/bash
CoreELEC:~/downloads #

Maybe entware (.opt, etc.) is influencing this?

Any “solution” for this?

Now using CoreELEC 20.0, ng, X905X3.

But /bin/sh is symbolic link to /bin/bash.

Anyway, it works here without entware installed and with entware installed with bash.
Maybe you have some strange character on first line in script file.

Post the content you get by command

hexdump -C test.sh

YOU ARE RIGHT!

CoreELEC:~/downloads # hexdump -C test.sh
00000000 23 21 2f 62 69 6e 2f 73 68 0a 65 63 68 6f 20 e2 |#!/bin/sh.echo .|
00000010 80 9c 48 65 6c 6c 6f 20 77 6f 72 6c 64 21 e2 80 |…Hello world!..|
00000020 9d |.|
00000021
CoreELEC:~/downloads #

dos2unix is useful here:

CoreELEC:~/downloads # ./test.sh
-sh: ./test.sh: /bin/sh: bad interpreter: Text file busy
CoreELEC:~/downloads # dos2unix test.sh
CoreELEC:~/downloads # ./test.sh
“Hello world!”
CoreELEC:~/downloads #

Perhahs dos2unix is necessary here because I create the script from samba / Windows 10?