Crontab for remote Hailo AI hat access

My main goal is to have my ai detector run remotely in the farm once I connect it to the battery without me entering 3 commands: (cd /home/omid/hailo-rpi5-examples), then I need to enter a virtual environment (source setup_env.sh) finally I need to run (python basic_pipelines/abcd.py —input rpi) to run my system.
How would I make it so that I can access the commands without connecting my raspberry pi to a mouse, keyboard and monitor.
I also want to run this command for 1 hour every day at 8:00 am is it possible to run it using crontab since I’ve tried the whole day asking ChatGPT for help and following its instructions is this idea even feasible please help asap whenever I run the commands manually on ternminal my AI detector works perfectly fine, but whenever crontab tries to automate the three commands it does not work

Edit: I feel like this is a virtual environment issue but I have no idea how to achieve my goal as I am a complete beginner

Can it be done, probably.
I think the commands would need to be in a script so they run one after the other in the same process and are associated with each other. Separate Con Jobs would not work. CronTab can be very confusing to start with, maybe try something very simple and see if it works. Also checking syslog will reveal if CronTab had a problem when running.

The linux CronTab manual page is a much better source than ChatGPT for information on CronTab. In fact anything is better than ChatGPT, AI doesn’t check whether the information it presents is valid or not and does not cross reference any of it. ChatGPT is full of misinformation just like YouTube videos on how to do something.

Maybe one day it will be better.

Regards
Jim

Hi @Ali286575

Welcome to the forum!

One option to do what you’re looking to do is to create a shell script, name it what you would like eg. hailo_start.sh and add the below code

#!/bin/bash

# Change directory
cd /home/omid/hailo-rpi5-examples

# Source the environment
source setup_env.sh

# Define the end time, 1 hour from now
end_time=$(( $(date +%s) + 3600 ))

while [ $(date +%s) -lt $end_time ]; do
    # Run the Python script
    python basic_pipelines/abcd.py --input rpi

done

If you then schedule a cron job

crontab -e

and enter this command

0 8 * * * /bin/bash /path/to/hailo_start.sh 
#Make sure that you update this to the actual path for your script

This should be able to run those commands for an hour every day at 8.