How to Automatically Run a Terminal Command on Raspberry Pi Startup?

0
12
Asked By TechyNerd123 On

Hi there! I'm new to Linux and I'm using Raspberry Pi OS on my Raspberry Pi. I'm looking for a way to make a script that runs a terminal command every time the OS boots up, just to simplify my workflow. The command I want to use is for the Raspberry Pi Camera module, specifically "rpicam-still -t 0". I've tried using crontab, but all the examples I found seem to deal with actual programs rather than straightforward terminal commands. I also tried editing the rc.local file to add the command, but it didn't work either. I'm really stuck and could use some guidance on what I might be doing wrong or what my next steps should be.

4 Answers

Answered By PixelPioneer99 On

Is "rpicam" not a binary? It should run directly as a program. You might want to try piping it to bash if you're focusing on terminal execution.

Answered By LinuxLover42 On

Have you thought about creating a bash script for your command? You could then set it up with crontab to execute on boot. That might get around the issues you're facing.

Answered By GadgetGuru77 On

Every terminal command is essentially a program, except for a few like `echo`. If you want to use rc.local, double-check that you've got it right and maybe use the full path for your command.

Answered By PiWhizKid On

Using rc.local is getting a bit outdated for many distros now. To use it, make sure your rc.local file starts with `#!/bin/bash`, is executable, and that the rc.local service is enabled. Also, does your command need to be run as root? If it needs to run upon your user logging in, consider creating a custom .desktop file in either `.local/share/autostart` or `/etc/xdg/autostart`. You might also explore making a custom service for your command.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.