0

A pair of my Python scripts are,
pyserial.py
predict.py

My bash.sh looks like :

#!/bin/sh 
python3 path/pyserial.py & 
python3 path/predict.py &

To run the bash on startup I edited crontab as,
@reboot sh path/bash.sh &

But on startup, only pyserial.py runs. Surprisingly, if I run the bash script using terminal as,
sh path/bash.sh
then both run. But on startup only the pyserial.py runs. What can I do ?

user3666197
  • 1
  • 6
  • 50
  • 92
FarhanAvro
  • 11
  • 2
  • Why not run both scripts directly from cron without the bash wrapper script? – mashuptwice Mar 26 '22 at 12:47
  • Shall I put @reboot python3 path/code.py & in Crontab ? – FarhanAvro Mar 26 '22 at 12:51
  • Remove `&` from the last line, or just run both of them as cron jobs. – zaibaq Mar 26 '22 at 12:53
  • First of all, you should put the proper shebang in your python script: `#!/usr/bin/env python` Then make it executable. After that you can run the script at reboot by adding `@reboot /path/to/your/script.py` in your crontab. – mashuptwice Mar 26 '22 at 12:54
  • I did these all. Now I think there might be a problem with my pyserial.py. because now i am trying with 3 files. 2 runs simultaneously but pyserial.py does not start. Although pyserial.py runs on its own just fine ! – FarhanAvro Mar 26 '22 at 12:58
  • The file is executable. When I execute it 3 files starts running. But at startup only 2 starts running. – FarhanAvro Mar 26 '22 at 13:12
  • 1
    You can always add `>> /some/log/file.txt` to the end of your cron statement to write to a logfile. – mashuptwice Mar 26 '22 at 13:41
  • @FarhanAvro Try to add `sleep 20` before the cronjob: `@reboot sleep 20 && sh path/bash.sh &`. pyserial.py might be not working because it (as its name says) connects to a serial port which might not yet be ready when the script starts immediately at boot up. – zaibaq Mar 26 '22 at 14:50

0 Answers0