1

New here and know that launching programs is a well discussed topic, but I've got a slightly different need that I think is complicating the solution.

I've got a straight forward python script that is run using an input from a USB device (Bar Code Scanner) and I'm using to actuate another device using the GPIO interface. The desired function is for this program to run in the command line (headless) once all resources are available.

I've tried several other solutions like modifying my program to run using Crontab, rc.local, and other well discussed solutions but it seems either my home directory is not yet available or the boot order means that the input device isn't available yet. None of the solutions described earlier resulted in an error message or the desired function.

Continuing to look for an answer independently, ideas or resource material would be appreciated.

PSCampbell
  • 109
  • 3

2 Answers2

1

You said you "... tried modifying my program to run using Crontab". Not certain exactly what that means, and you didn't show us what you tried, but you've supplied no reason that it shouldn't work. And so I'll suggest that you try it again, using something like this in your crontab

@reboot /bin/sleep N; /path/to/your/yourPythonscript

Where N is the number of seconds to sleep (10-15 secs is usually sufficient, but depending on your hardware, it may take longer) See man sleep for more details

sleep simply suspends your shell for the time specified while your systems marshals other resources during the boot process. This is necessary as cron regards @reboot to be the time that it's spawned, without regard to the availability of other resources. That said, cron is IMHO, the safest and easiest way to start things after a reboot.

Hope that helps.

ADDENDUM:

If you launch your program from .bashrc it may execute when you don't expect it to. Read man bash for details.

Seamus
  • 23,558
  • 5
  • 42
  • 83
-2

Well, I found my answer and sheepishly leaving it here for future Googlers:

I should have added the program to my .bashrc, which is pretty much the only method that I didn't attempt prior to posting. I found a decent tutorial on the various methods of accomplishing what I was needing here

PSCampbell
  • 109
  • 3