Running terminal commands at startup

i want to run terminal coomand at startup which should play 3 mp3 files automatically at startup during boot in an infinit loop with omxplayer. plz anybody guide how can i achieve this. i was thinking of rc.local but its depreceated

Hi,

first you would need to the command to have you like to execute. If this is working already, you have basically 3 options.

  1. execute the command on boot using crontab
  2. create your own systemd service
  3. use DietPi auto start function (Custom script)

Generally you can also create scripts in /var/lib/dietpi/postboot.d/, but as long as the scripts run, the login prompt is delayed. So this seems not appropriate for your case as long as you cannot fork the playback loop into background within the script. The crontab @reboot function has a similar issue AFAIK, as those are executed one after another, so one running process blocks others from being executed.

For job that should run longer or forever in background, an own systemd service or dietpi-autostart custom script option are indeed the best fitting methods, as this is precisely what they are meant for.

Hi all

New to the forum and DietPi - I have a similar requirement and not sure the easiest way to do it

Basically, I have RPI model B with DietPi installed and also Wordgrinder installed via ā€˜apt installā€™ all works well from terminal

My aim is to use this old RPI as a basic portable word processor using Wordgrinder

I already have the DietPi boot to terminal and would like to make it autostart Wordgrinder on boot
(if I need other programs I can exit Wordgrinder and just use terminal)

Just looking for the easiest way to do this

Thanks in advance for help :slight_smile:

what is the command you like to run on boot?

Just to autostart the program Wordgrinder

To start in terminal the command is simply ā€˜wordgrinderā€™

:slight_smile:

Was thinking there may be a simple command

(like there used to be in old Windows DOS where you just add the program executable as the last line, think it was either the autoexec.bat or config file)

to start the program once boot process is completed?

in terminal, type type wordgrinder to see fullpath to wordgrinder command

then: crontab -e

add the line
@reboot /path/to/wordgrinder and replace the path with the path you got earlier.
press CTRL + X
and confirm your change with ā€˜Yā€™ button.

This should do it

Thanks :slight_smile:
Iā€™ll try that shortly and report back

you could try following as well

dietpi-autostart > 17 : Custom script

This should open a template script. Add your start command using the full path /path/to/wordgrinder. Save the file and reboot.

Well crontab edit didnā€™t work :frowning:

I thought it would as it appears a similar process to when I used to edit the old Windows autoexec files

To be clear, I queried the full path and got:
/usr/bin/wordgrinder

Then crontab -e to edit the cron file, and added as the last (the only non commented out line):
@reboot /usr/bin/wordgrinder

Then exit (ctrl x) and save when prompted (y) and enter

But on reboot - nothing, just logged in as root (autologin set) to command line

Will try the autostart custom script and see if that works

dietpi-autostart > custom script worked a treat! :slight_smile:

Thanks for the help guys!!

Just need to find or modify a smallish display and built a box (cigarbox size-ish)

Should I remove the line I put in the crontab as I am using the custom script method?

yes could be removed from crontab

Thanks! :slight_smile:

Regarding dietpi-autostart: Sorry I have a question here as well. I am a little bit confused about auto login and foreground process!

  1. DietPi Starts, script should run from /root/tool.sh with root rights. This should work automatically during every boot, I start a socket communication ending up in a rsnapshot run
  2. If I need to log in in parallel via ssh, this should be possible

Is this exactly what I can achieve with ā€œdietPi-autostartā€ tool?

This is my script:

#!/bin/bash
# DietPi-Autostart custom script
# Location: /var/lib/dietpi/dietpi-autostart/custom.sh

# starts socket communication to server and starts rsnapshot job with weekly, monthly or yearly argument and verbose
python /root/runDietPiBKServerII_SocketClient.py
# shut down system when no other user is logged in
/root/poweroffIfNoUserIsLoggedIn.sh

exit 0

The poweroff script worked on my synology I hope it will work here as well. The socket communication is necessary because I split the job on two raspberry pis. One to rsync every time I plug in my USB stick, and a cron job running on it (weekly, monthly and yearly), to power on automatically via relay the second pi and after establishing socket communication start the related rsnapshot job!

This is something Iā€™d run with the dietpi-autostart custom background option. There is no need in this case to login on local console and lock it with a foreground script. That way SSH (anyway) and also the local console (keyboard + screen login) can be used freely.

1 Like

Hi @MichaIng ! I am not sure, if I understood right. In my case the script is set for foreground and for background processes to be custom.sh! So how could I disable or enable the one or the other?? I guess I have missed up a point somewhere hereā€¦

I mean, it is actually not working if I reboot! How can I prove? In which log are my echoes?
At the moment I can go to foreground script or to background, it always takes my created custom.sh!! It does not tell me which job it will start in the endā€¦Normally my assumption is the follwoing: dietpi-autostart would ask me each time which script to choose and after saving, it will give a status, that the script will be started during next reboot. If I switch to background after I configured foreground it should repeat the same steps. And if I walk in the next time, first thing should be: ask if I want to cancel the job or just changeā€¦ So at the moment I am stuck.

Both autostart options execute the custom.sh. When choosing the background option, check

journalctl -u dietpi-autostart_custom
1 Like