how to auto run .sh file when TX2 board power on?
Can it run as root, or do you need it to run as a particular user? A typical “simple” method (if there are no special dependencies) would be to name the full path in “
hi , there is not a file named “
/etc/rc.local ” under /etc. i use jetpack4.4,L4T32.4.3
- should i have to touch a file named rc.local under /etc?
2.i just want to use can module on TX2, so i want to modprobe can modules such as mttcan when powerd on with my.sh, as a root user.
Creating the file with “
sudo touch /etc/rc.local” (not as a regular user) would probably be ok, but you’d want the first 2 lines to be (second line is comment or nothing active or blank):
#!/bin/sh -e # # Perhaps this as an example of file to run if it is a bash scrpt: /bin/bash /usr/local/etc/YourScriptFile.sh
Sorry, this turned out a bit more complicated than expected in the explanation below due to phasing out old style init scripts for
systemd services. Information follows since it might be useful to have this on the forums anyway for people working with
I see there is also a systemd service for “
rc-local.service” which is now responsible for actually running
rc.local content when boot reaches the correct stage, and so after doing this you might report what you see from:
sudo systemctl status rc-local.service
(this used to trigger running via an init script file instead of systemd services)
If the service is not running, then:
sudo systemctl enable rc-local.service sudo systemctl start rc-local.service # Verify it runs: sudo systemctl status rc-local.service
Note: It used to be
rc.local was always there (despite being empty other than the first line), but it seems some newer releases are treating this as “legacy” such that “
/etc/rc.local” does not always run (does not always exist) unless someone manually configures it to do so (a sign that old style init scripts are being completely phased out). The “
rc.local” file is part of the old “init” style scripts, whereas “
systemd” is the new way of deciding what and when to run content during boot (under
systemd you’d create a service for the file you are interested in running rather than simply naming it in
rc.local should be simpler).
Basically you can create the file “
/etc/rc.local” as a bash script file (which is why it starts with “
/bin/sh -e”). I may be missing some details on this when run as a service, so if you get errors we can go from there. Just make sure to copy and paste any error you see.
Note: The “status” shown from “
systemctl status...” mentions using “
sudo systemctl daemon-reload”, but I think this will happen anyway when you reboot. You could run this if you want to anyway once you’ve enabled the service.
#/bin/sh -e” file of the “shebang” is a restricted version of “
/bin/bash” used for non-login accounts. However, if you need “
/bin/bash”, then you can use this in the actual command which runs your program on another line of the file rather than the
rc.local as a whole. Example:
#!/bin/sh -e # /bin/bash /usr/local/etc/hello_world.sh
If you wanted to disable this:
sudo systemctl disable rc-local.service sudo systemctl stop rc-local.service
You might want to look at setting up a login with auto-login, and then setting up a default app to run.
You might be looking for kiosk mode.