I need to set an environment variable and run an app when the Raspberry Pi boots up. To that end, I added the following to /home/pi/.bashrc:
export MY_ENV_VAR=foo
cd /home/pi/MyApp
./MyApp
When I reboot the Pi, the app is definitely running and the environment variable is set. However, when I log in, the application is executed again - e.g. .bashrc is run on both login and boot.
How can I ensure that my script is only executed once at boot time and not at login?
P.S. I've tried copying the script /etc/rc.local, but then it doesn't run at all.
– AngryHacker Aug 09 '21 at 05:54@reboot export MY_ENV_VAR=foo && cd /home/pi/MyApp && ./MyApp~/MyAppwas all that was needed. Setting an environment variable is a different thing. Do you want the environment variable to be global (system-wide), or just during execution of your program? – Seamus Aug 09 '21 at 06:23piuser rather than root. Is that as simple as running crontab assudo crontab -u pi -e? – AngryHacker Aug 09 '21 at 15:25I'd like the app to run under the pi user rather than root?!? Unless I missed something you have never mentioned running as root. – Seamus Aug 09 '21 at 18:12