How to run commands on startup

Quick to answer questions about finding your way around Linux Mint as a new user.
Forum rules
There are no such things as "stupid" questions. However if you think your question is a bit stupid, then this is the right place for you to post it. Stick to easy to-the-point questions that you feel people can answer fast. For long and complicated questions use the other forums in the support section.
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
Taffman

How to run commands on startup

Post by Taffman »

I need to run the following commands each time I boot up:

sudo setserial /dev/ttyS4 uart 16550A
sudo setserial /dev/ttyS5 uart 16550A
sudo setserial /dev/ttyS6 uart 16550A
sudo setserial /dev/ttyS7 uart 16550A

I have tried adding them to /etc/rc.local but i don't think Mint reads this file on startup.

an anyone tell me where I can store the above commands so that they are executed on startup please?
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
russellz
Level 3
Level 3
Posts: 174
Joined: Sat Nov 24, 2012 7:02 am
Location: Millas, France

Re: How to run commands on startup

Post by russellz »

Try /etc/init.d/rc.local ?

Russell.
Laptop: HP17bs086nf, Intel Core i5-7200U, Intel HD Graphics 620 . Mint Cinnamon 21.1
Desktop: ASUS Prime B760-plus D4 motherboard, AMD Radeon RX6500XT, Intel 12th gen i7 12 core 3500MHz, 8GB ram, 500GB Samsung SSD, Mint Cinnamon 21.1
viking777

Re: How to run commands on startup

Post by viking777 »

Commands executed from /etc/rc.local (or /etc/init.d/rc.local if you decide to try that) are run as root so they do not require sudo. Remove sudo from the commands and see if it makes any difference - I don't know if it will, but it is worth a try.
Taffman

Re: How to run commands on startup

Post by Taffman »

Nope, that didn't work either.
viking777

Re: How to run commands on startup

Post by viking777 »

OK lets start with the simple questions - have you tried running these commands after startup from a terminal and if so do they work - you haven't said. Without an answer to that question everything else is irrelevant.
Taffman

Re: How to run commands on startup

Post by Taffman »

These commands work when manually entered in Terminal.
but these settings do not persist after a reboot.


not sure if I need "sudo" here though, i do in Terminal from my user account.
viking777

Re: How to run commands on startup

Post by viking777 »

OK this is what I would try:

Make a shell script from the commands you want to run:

Code: Select all

#!/bin/bash

setserial /dev/ttyS4 uart 16550A
setserial /dev/ttyS5 uart 16550A
setserial /dev/ttyS6 uart 16550A
setserial /dev/ttyS7 uart 16550A
Save it as setserial.sh and make it executable. If, as you say above you don't need sudo to run these commands you can save it to your home folder.

Now go to the program 'Startup Application' and add a new entry. Call it Setserial (or anything you like it doesn't matter) make the command to run

Code: Select all

/home/yourusername/setserial.sh
I hope you appreaciate that it has to be your real username, not what I have just typed.

I start several programs this way and it always works for me, if it doesn't then it may be a permissions issue in which case my instinct would be to move setserial.sh to /usr/bin and change the ownership to root. I don't know if this works - I have never tried it.
Taffman

Re: How to run commands on startup

Post by Taffman »

Ok I'll try that. thanks for your help.
Taffman

Re: How to run commands on startup

Post by Taffman »

I cant seem to get any scripts to run on startup using the Startup Applications menu option or by adding commands to /etc/rc.local
Anyone know the trick to this?
bigj231

Re: How to run commands on startup

Post by bigj231 »

Did you set the script to executable?

Code: Select all

chmod 775 yourscriptnamehere
Taffman

Re: How to run commands on startup

Post by Taffman »

Yep tried that still doesn't work.
johnywhy

Re: How to run commands on startup

Post by johnywhy »

for those looking here for a solution:
Open the "Session and Startup" application.
Go to the "Application Autostart" tab.
Add each command as a separate entry.
Done.
Habitual

Re: How to run commands on startup

Post by Habitual »

Taffman wrote:Nope, that didn't work either.
try /path/to/setserial on each of those lines in /etc/rc.local or in the script if one is used for it in /etc/rc.local
amit_27
Level 1
Level 1
Posts: 14
Joined: Sun Jun 26, 2016 1:38 am

Re: How to run commands on startup

Post by amit_27 »

johnywhy wrote: Thu Jun 18, 2015 7:31 pm for those looking here for a solution:
Open the "Session and Startup" application.
Go to the "Application Autostart" tab.
Add each command as a separate entry.
Done.
Thank you! I was looking at this post for a solution. This worked really well for me. Much appreciated :)
Locked

Return to “Beginner Questions”