How can you run an interactive script on boot with no monitor plugged in?

April 5, 2023, 00:45

cpogfrey

I feel like this should be a common use case for a raspberry pi, I'm surprised how hard it is. I have a raspberry pi 3a+ and a python script that runs auxiliary hardware plugged into the pi (I don't think the specifics of those are too important). Then I have one of these three-key USB mini-keyboards plugged directly into the PI, and based on the input from those keys, the python script does things with the auxiliary hardware. The only problem is that it requires booting up a terminal and manually running the script. Ideally, as soon as the pi turns on, the script would run and start polling for input with just the usb keyboard and auxiliary hardware plugged in, no monitor necessary. [Tried] Using a cronjob with @reboot seems to be a deadend because they run in the background and can't take user input [Tried] Using rc.local seems to fail for a similar reason [Tried] Putting the script in .bashrc seemed like it failed, but I was having trouble finding the logs to figure out what might've gone wrong [Haven't tried] Using systemctl by specifying StandardInput=tty seems like it might work, though I'm concerned that there is no tty to connect to since there's no monitor/ssh connection (I don't know the details of how this works) * [Haven't tried] Using openvt to create a new VT as mentioned at https://superuser.com/questions/584931/howto-start-an-interactive-script-at-ubuntu-startup seems promising Ideally, I could just go through all these option. The issue is, I'm helping a friend work this out virtually, which means I'm telling them what to do and that makes the debug process painfully slow. I'd like to hear some advice from the people here on what seems feasible, or if there's a different approach altogether that might be better.

illegitimate_egg

You can create a service or use cron

cpogfrey

I tried with cron, it seems like the cronjob runs in the background and can't take user input

illegitimate_egg

You want it to take user input?

illegitimate_egg

Well

illegitimate_egg

as long as a shell loads on tty 1

illegitimate_egg

you can put it into .bashrc

illegitimate_egg

but it would need to automatically login

illegitimate_egg

which is possible

cpogfrey

hmm, I'm pretty sure it auto-logs in, at least with the monitor plugged in. Will have to double check that

illegitimate_egg

You would know if it auto logs in

illegitimate_egg

because you have to set that up manually

cpogfrey

we bought it used, so it might've been set up that way

illegitimate_egg

you didn't wipe the card first?

oops.se

And check out
screen
or does it need to be a GUI?