Mycroft Community Forum

Prompt skill from Cron Job

Hi guys, I have a skill with a function I’d like executed from a script that needs to be run every minute. I have this set to be done via cron. I have a LOG statement in the function to check that the script works. The cron job runs the scripts but no LOG message appears. However if I run the script manually, I can get the LOG message. I’m stumped. Here is some information that should help.

crontab

* * * * * python3 /opt/mycroft/skills/my-skill/scripts/my-script.py

my-script.py

import os
os.system("python3 -m mycroft.messagebus.send 'test'")

my-skill/init.py

    def initialize(self):
       self.add_event('test', self.handler_test)

    def handler_test(self):
       LOG.info("Hello!")
       self.speak("Hello world!")

All help is appreciated thank you!

You most likely need to set;

PYTHONUNBUFFERED=TRUE

In your python environment variable to see it straight away via cron.

Or at least that is what is needed if you want to send the output to journald if you run it via systemd. Guess, cron needs the same. For file output it is not needed.

I don’t think I phrased my question correctly. I want the skill to be prompted when the cron job executes my python script. If I look at /var/log/mycroft/skills.log I can see the skill starting but the LOG statement ‘Hello!’ doesn’t come through. If I have the mycroft-cli open I also don’t get any output via the speak function in the ‘test’ handler.
I don’t know why this is the case as when I run the python script manually via:

python3 -m mycroft.messagebus.send ‘test’

from the ‘skill-scripts’ directory I have set up, I can get both the LOG statement ‘Hello!’ in skills.log, and ‘Hello world!’ in the mycroft-cli.

Ah ok!

Do you run within the venv environment?

I am running within the venv environment yes.

Hmm, sorry, then I am already out of ideas.

My python knowledge is really not that great🤨

No worries thanks for the help! Switched from a python script to a bash script and it works! I set it to be executable with the following:

script.sh

#!/bin/bash
python3 -m mycroft.messagebus.send 'test'

crontab

SHELL=/bin/bash
PATH=/home/pi/bin/mycroft-core/.venv/bin
* * * * * /opt/mycroft/skills/my-skill/scripts/script.sh