# Shell Script to Run at Boot

**URL:** <https://rpi-rgb-led-matrix.discourse.group/t/shell-script-to-run-at-boot/178>\
**Category:** Uncategorized\
**Created:** [March 26, 2021, 2:58am UTC](https://rpi-rgb-led-matrix.discourse.group/t/shell-script-to-run-at-boot/178 "2021-03-26T02:58:10Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![porky](https://avatars.discourse-cdn.com/v4/letter/p/919ad9/32.png) [@porky](https://rpi-rgb-led-matrix.discourse.group/u/porky)\
**Post date:** [March 26, 2021, 2:58am UTC](https://rpi-rgb-led-matrix.discourse.group/t/shell-script-to-run-at-boot/178/1 "2021-03-26T02:58:11Z")

</div>

Hi everyone. I have tried to add my python script to systemd to run as my ras-pi boots. However, I have not been able to figure out where/how to add the additional arguments such as “–led-cols=64” and so on in that script. If anyone else has this figured out and would like to pass along their knowledge that would be much appreciated.

On a similar note, is there a way to include arguments such as --led-brightness in the python script? I am trying to change the brightness of the display based off the current time and have not been able to figure out how.

---

<div class="post-metadata">

**Author:** ![AxelH](https://avatars.discourse-cdn.com/v4/letter/a/cdc98d/32.png) [@AxelH](https://rpi-rgb-led-matrix.discourse.group/u/AxelH)\
**Post date:** [March 26, 2021, 9:06am UTC](https://rpi-rgb-led-matrix.discourse.group/t/shell-script-to-run-at-boot/178/2 "2021-03-26T09:06:38Z")

</div>

Hi porky,

You can find python examples in the bindings directory :

> <https://github.com/hzeller/rpi-rgb-led-matrix/blob/master/bindings/python/samples/image-draw.py>

And change options like this :  
\> # Configuration for the matrix

> ```
> options = RGBMatrixOptions()
> options.rows = 32
> options.chain_length = 1
> options.parallel = 1
> options.hardware_mapping = 'regular' # If you have an Adafruit HAT: 'adafruit-hat'
> 
> ```

For brightness in python see this :

> <https://github.com/hzeller/rpi-rgb-led-matrix/blob/master/bindings/python/samples/pulsing-brightness.py>

Hope it’ll help you 😁

---

<div class="post-metadata">

**Author:** ![zenoshrdlu](https://avatars.discourse-cdn.com/v4/letter/z/0ea827/32.png) [@zenoshrdlu](https://rpi-rgb-led-matrix.discourse.group/u/zenoshrdlu)\
**Post date:** [March 26, 2021, 6:00pm UTC](https://rpi-rgb-led-matrix.discourse.group/t/shell-script-to-run-at-boot/178/3 "2021-03-26T18:00:42Z")

</div>

Not quite what you want, but I use the /etc/rc.local file to set things up on a boot or reboot. Here’s the key lines:  
cd /home/pi/ftp/files/rpi-fb-matrix  
sudo ./rpi-fb-matrix --led-brightness=75 --led-slowdown-gpio=2 matrix64.cfg&  
That ampersand means the rpi-fb-matrix app runs in the background so that anything sent via hdmi will get displayed on the matrix panels (in my case four 64\*64 panels).

I’ve also arranged that whenever a USB storage device (eg thumbdrive) is plugged into the pi, devmon detects this and automatically runs a playlist of videos if the drive contains one.

---

<div class="post-metadata">

**Author:** ![marcmerlin](https://yyz2.discourse-cdn.com/free1/user_avatar/rpi-rgb-led-matrix.discourse.group/marcmerlin/32/40_2.png) [@marcmerlin](https://rpi-rgb-led-matrix.discourse.group/u/marcmerlin)\
**Post date:** [March 27, 2021, 3:17am UTC](https://rpi-rgb-led-matrix.discourse.group/t/shell-script-to-run-at-boot/178/4 "2021-03-27T03:17:53Z")

</div>

I also like to add a ‘sleep 30’ before starting any code, because rgb-panel code can overwhelm the CPU in a way that wifi stops working and you can’t ssh in anymore, so it’s useful to be able to ssh in and disable stuff in 30sec before the device gets wedged 🙂

---

<div class="post-metadata">

**Author:** ![jayrankin](https://avatars.discourse-cdn.com/v4/letter/j/a6a055/32.png) [@jayrankin](https://rpi-rgb-led-matrix.discourse.group/u/jayrankin)\
**Post date:** [March 30, 2021, 6:05pm UTC](https://rpi-rgb-led-matrix.discourse.group/t/shell-script-to-run-at-boot/178/5 "2021-03-30T18:05:31Z")

</div>

hello,  
im researching through the posts for ideas, im a complete newbie (started an online python boot camp this week)  
One of the things im looking to do is have the image-viewer display a file (png or gif) that would be displayed on the second HDMI port of a pi4.  
OR  
ignore the HDMI port and just display direct to the LEDs…

am i reading write the code example you gave displays whatever is on the HDMI to the LEDs by listening?  
cd /home/pi/ftp/files/rpi-fb-matrix  
sudo ./rpi-fb-matrix --led-brightness=75 --led-slowdown-gpio=2 matrix64.cfg&

if so, does this mean i can have this code in a startup script and then it will output?

thanks in advance

---

<div class="post-metadata">

**Author:** ![zenoshrdlu](https://avatars.discourse-cdn.com/v4/letter/z/0ea827/32.png) [@zenoshrdlu](https://rpi-rgb-led-matrix.discourse.group/u/zenoshrdlu)\
**Post date:** [March 30, 2021, 7:25pm UTC](https://rpi-rgb-led-matrix.discourse.group/t/shell-script-to-run-at-boot/178/6 "2021-03-30T19:25:23Z")

</div>

Yes - that rpi-fb-matrix app runs in the background and intercepts and copies whatever is sent to the hdmi port to the led panels. Works for movies and still images. It works even if there is no monitor attached to the hdmi port.

---

<div class="post-metadata">

**Author:** ![jayrankin](https://avatars.discourse-cdn.com/v4/letter/j/a6a055/32.png) [@jayrankin](https://rpi-rgb-led-matrix.discourse.group/u/jayrankin)\
**Post date:** [March 30, 2021, 8:23pm UTC](https://rpi-rgb-led-matrix.discourse.group/t/shell-script-to-run-at-boot/178/7 "2021-03-30T20:23:53Z")

</div>

great and thanks for the quick reply! is there a way to specific which hdmi port? for the Pi4?  
and is there a way to add a second HDMI port (virtually) for Pi3 and use this?  
this could be my arcade leds answer! 🙂  
thanks again

---

<div class="post-metadata">

**Author:** ![zenoshrdlu](https://avatars.discourse-cdn.com/v4/letter/z/0ea827/32.png) [@zenoshrdlu](https://rpi-rgb-led-matrix.discourse.group/u/zenoshrdlu)\
**Post date:** [March 30, 2021, 10:04pm UTC](https://rpi-rgb-led-matrix.discourse.group/t/shell-script-to-run-at-boot/178/8 "2021-03-30T22:04:04Z")

</div>

Hi Jay

I’m using a Pi 4 which hasd two cdmi ports. I play videos using omxplayer which lets you choose which had port to use - [see this page](https://www.raspberrypi.org/documentation/raspbian/applications/omxplayer.md).

Dave

---

<div class="post-metadata">

**Author:** ![jayrankin](https://avatars.discourse-cdn.com/v4/letter/j/a6a055/32.png) [@jayrankin](https://rpi-rgb-led-matrix.discourse.group/u/jayrankin)\
**Post date:** [March 31, 2021, 1:08am UTC](https://rpi-rgb-led-matrix.discourse.group/t/shell-script-to-run-at-boot/178/9 "2021-03-31T01:08:04Z")

</div>

Thanks for sharing…  
How would one send to the second display and then have rpm matrix display it then?  
I can send a file to the second display using omxplayer but I would like the led matrix to display the same thing? Sorry for keep asking…  
I looked at the rip matrix and couldn’t find a switch to select hdmi?

---

<div class="post-metadata">

**Author:** ![zenoshrdlu](https://avatars.discourse-cdn.com/v4/letter/z/0ea827/32.png) [@zenoshrdlu](https://rpi-rgb-led-matrix.discourse.group/u/zenoshrdlu)\
**Post date:** [April 5, 2021, 11:49am UTC](https://rpi-rgb-led-matrix.discourse.group/t/shell-script-to-run-at-boot/178/10 "2021-04-05T11:49:15Z")

</div>

Jay - I need more information before I can help:

1. which version of raspbian are you running - raspbian\_lite? If so you are running headless (which is good)
2. do you/can you use ssh and the terminal app on your pc to log on to the pi? (  
If you can then you can issue commands to the pi to cancel running apps and start new ones.

---

<div class="post-metadata">

**Author:** ![jayrankin](https://avatars.discourse-cdn.com/v4/letter/j/a6a055/32.png) [@jayrankin](https://rpi-rgb-led-matrix.discourse.group/u/jayrankin)\
**Post date:** [April 5, 2021, 8:08pm UTC](https://rpi-rgb-led-matrix.discourse.group/t/shell-script-to-run-at-boot/178/11 "2021-04-05T20:08:13Z")

</div>

hey,  
Thanks for reply/help…i can SSH into the PI.  
As i said i would like to mirror the second HDMI not the primary to the RGB…the software im using for the second display shows either gif/PNG files as i change menus on the main screen…  
Its retropie…using emulation station…so when i choose a game or emulator the script chooses the PNg/gif and displays it on the second HDMI…  
therefore i would like to mirror the HDMI output to the RGB… 🙂 .

---

<div class="post-metadata">

**Author:** ![zenoshrdlu](https://avatars.discourse-cdn.com/v4/letter/z/0ea827/32.png) [@zenoshrdlu](https://rpi-rgb-led-matrix.discourse.group/u/zenoshrdlu)\
**Post date:** [April 6, 2021, 3:47pm UTC](https://rpi-rgb-led-matrix.discourse.group/t/shell-script-to-run-at-boot/178/12 "2021-04-06T15:47:12Z")

</div>

I’m not sure if this will help but there are options in the /boot/config.txt file to do with hdmi. See  
[Video options in config.txt - Raspberry Pi Documentation](https://www.raspberrypi.org/documentation/configuration/config-txt/video.md)  
for information.

In my case I have:  
hdmi\_force\_hotplug=1  
hdmi\_group=2  
hdmi\_mode=87  
hdmi\_cvt 1024 2014 60 6 0 0 0

Dave

---

<div class="post-metadata">

**Author:** ![Stargazer2022](https://avatars.discourse-cdn.com/v4/letter/s/9de053/32.png) [@Stargazer2022](https://rpi-rgb-led-matrix.discourse.group/u/Stargazer2022)\
**Post date:** [January 3, 2022, 1:46am UTC](https://rpi-rgb-led-matrix.discourse.group/t/shell-script-to-run-at-boot/178/13 "2022-01-03T01:46:49Z")

</div>

Just want to thank you for your help with this problem.  
There’s just no specific info out there on the syntax to make it autostart. Thanks to you it’s now working!

---

<div class="post-metadata">

**Author:** ![ShuraBlack](https://yyz2.discourse-cdn.com/free1/user_avatar/rpi-rgb-led-matrix.discourse.group/shurablack/32/366_2.png) [@ShuraBlack](https://rpi-rgb-led-matrix.discourse.group/u/ShuraBlack)\
**Post date:** [July 14, 2024, 3:03am UTC](https://rpi-rgb-led-matrix.discourse.group/t/shell-script-to-run-at-boot/178/14 "2024-07-14T03:03:51Z")

</div>

This is an old post, but if anyone does have the same question, i solved this via the linux services.

1. Open up a root bash with `sudo bash` or `sudo su`

2. Create a bash script with your command in the desirable location  
e.g. /usr/local/sbin/

```auto
#!/bin/bash
screen -DmS <screen-name> <command>

```

Make sure you got screen installed if you want to do it like that. I use it to attach back into the process after starting, to read the logs afterwards or interact with the cli (`screen -r <name-of-service>`. As a tip, use Ctrl+A then D to escape xD).

1. Create an .service file under etc/systemd/system/  
e.g.

```auto
# <your-service-name>
[Unit]
Description=<your-description>
After=multi-user.target

[Service]
Type=idle
ExecStart=<Path/to/bash/script>

[Install]
WantedBy=multi-user.target

```

1. Change the permissions of the two files with  
`chmod +x <path/to/the/files>`

2. Reload systemctl  
`systemctl daemon-reload`

3. (“Optional”) Test your service with  
`systemctl start <name>.service`

4. Enable your service  
`systemctl enable <name>.service`

5. Reboot 🙂

> **Keep in mind** , this is a super user service, since the api needs root previliges to initialize the hardware
