User avatar
thagrol
Posts: 6112
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

STICKY: Running A Program At Start UP A Beginner's Guide

Wed Jun 23, 2021 2:51 pm

Number four in an occasional series.
boot.zip
(169.63 KiB) Downloaded 324 times
Also on github: https://github.com/thagrol/Guides
I'm a volunteer. Take me for granted or abuse my support and I will walk away

All advice given is based on my experience. it worked for me, it may not work for you.
Need help? https://github.com/thagrol/Guides

User avatar
neilgl
Posts: 3666
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near The National Museum of Computing

Re: Running A Program At Start UP A Beginner's Guide

Wed Jun 23, 2021 3:40 pm

Excellent stuff, thanks.

deepo
Posts: 909
Joined: Sun Dec 30, 2018 8:36 pm
Location: Denmark

Re: Running A Program At Start UP A Beginner's Guide

Wed Jun 23, 2021 6:51 pm

That's good work!

katesimon123
Posts: 39
Joined: Sun Jun 13, 2021 2:45 am

Re: Running A Program At Start UP A Beginner's Guide

Wed Jun 23, 2021 7:52 pm

Good one, will test it out !!!

RonR
Posts: 2519
Joined: Tue Apr 12, 2016 10:29 pm
Location: US

Re: Running A Program At Start UP A Beginner's Guide

Wed Jun 23, 2021 8:25 pm

A && B || C : Do A, if A succeeds do B. If A failed do C

I believe this should be:

A && B || C : Do A, if A succeeds do B. If A or B failed do C

Code: Select all

root@FreePBX:~# true && true || echo "!"
root@FreePBX:~# true && false || echo "!"
!
root@FreePBX:~# false && true || echo "!"
!
root@FreePBX:~# false && false || echo "!"
!

User avatar
thagrol
Posts: 6112
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Running A Program At Start UP A Beginner's Guide

Wed Jun 23, 2021 9:28 pm

RonR wrote:
Wed Jun 23, 2021 8:25 pm
A && B || C : Do A, if A succeeds do B. If A failed do C

I believe this should be:

A && B || C : Do A, if A succeeds do B. If A or B failed do C

Code: Select all

root@FreePBX:~# true && true || echo "!"
root@FreePBX:~# true && false || echo "!"
!
root@FreePBX:~# false && true || echo "!"
!
root@FreePBX:~# false && false || echo "!"
!
Probably. Feel free to open an issue in my github.
I'm a volunteer. Take me for granted or abuse my support and I will walk away

All advice given is based on my experience. it worked for me, it may not work for you.
Need help? https://github.com/thagrol/Guides

bls
Posts: 1862
Joined: Mon Oct 22, 2018 11:25 pm
Location: Seattle, WA

Re: Running A Program At Start UP A Beginner's Guide

Wed Jun 23, 2021 9:40 pm

This is great, thagrol!
Pi tools:
Quickly and easily build customized-just-for-you SSDs/SD Cards: https://github.com/gitbls/sdm
Easily run and manage your network's DHCP/DNS servers on a Pi: https://github.com/gitbls/ndm
Easy and secure strongSwan VPN installer/manager: https://github.com/gitbls/pistrong
Lightweight Virtual VNC Config: https://github.com/gitbls/RPiVNCHowTo

strantor
Posts: 7
Joined: Thu Jun 17, 2021 9:17 pm

Re: STICKY: Running A Program At Start UP A Beginner's Guide

Thu Jul 08, 2021 7:20 pm

Very well put together and extremely helpful. Thank you so much for this resource! It got me where I needed to be in minutes, after wasting hours trying to follow other advice.

User avatar
DougieLawson
Posts: 41897
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: STICKY: Running A Program At Start UP A Beginner's Guide

Sun Aug 15, 2021 7:39 am

Why do you think it needs sudo? What root privileges does it need? Or do you have a bad case of sudoitis?
Why do you have a space between /usr/bin and /bash - that's never going to work sudo or not?
Languages using left-hand whitespace for syntax are ridiculous

DMs sent on Twitter/LinkedIn will be answered next month.
Fake doctors - are all on my foes list.

The use of crystal balls and mind reading is prohibited.

User avatar
thagrol
Posts: 6112
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: STICKY: Running A Program At Start UP A Beginner's Guide

Sun Aug 15, 2021 10:07 am

DougieLawson wrote:
Sun Aug 15, 2021 7:39 am
Why do you think it needs sudo? What root privileges does it need? Or do you have a bad case of sudoitis?
I'm guessing because
-c vtnumber
Use the given VT number and not the first available. Note you must have write access to the supplied VT for this to work.
which the pi user won't have unless logged in on tty2
I'm a volunteer. Take me for granted or abuse my support and I will walk away

All advice given is based on my experience. it worked for me, it may not work for you.
Need help? https://github.com/thagrol/Guides

User avatar
thagrol
Posts: 6112
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: STICKY: Running A Program At Start UP A Beginner's Guide

Sun Aug 15, 2021 10:23 am

DoubleD wrote:
Sun Aug 15, 2021 12:15 am

Code: Select all

sudo /usr/bin /bash -c '/usr/bin/openvt -c 2 -f -s -- /home.pi/{mybashscriptfile}.sh' 
I'd remove the space between /usr/bin and /bash. Actually I'd skip /usr/bin/bash -c and just call openvt with the correct path. On my system its in /bin not /usr/bin.

And replace "/home.pi" with "/home/pi"

Given that it's a bad idea to run your script as root, try something like this:

Code: Select all

sudo /bin/openvt -c 2 -f -s -- sudo -u pi -i /home/pi/{mybashscriptfile}.sh
If that works as desired, run it from a systemd service, root's crontab, or rc.local. In all cases the first sudo should be omitted.
I'm a volunteer. Take me for granted or abuse my support and I will walk away

All advice given is based on my experience. it worked for me, it may not work for you.
Need help? https://github.com/thagrol/Guides

DoubleD
Posts: 6
Joined: Fri Jun 01, 2018 2:29 pm

Re: STICKY: Running A Program At Start UP A Beginner's Guide

Wed Sep 01, 2021 2:29 pm

thagrol wrote:
Sun Aug 15, 2021 10:07 am
DougieLawson wrote:
Sun Aug 15, 2021 7:39 am
Why do you think it needs sudo? What root privileges does it need? Or do you have a bad case of sudoitis?
I'm guessing because
-c vtnumber
Use the given VT number and not the first available. Note you must have write access to the supplied VT for this to work.
which the pi user won't have unless logged in on tty2
The space was a typo. Sudo because it would not work unless I used sudo

I think you are correct about VT but I just reconfig the pi to boot cli and used .profile to kick it off

User avatar
thagrol
Posts: 6112
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: STICKY: Running A Program At Start UP A Beginner's Guide

Wed Sep 01, 2021 3:24 pm

DoubleD wrote:
Wed Sep 01, 2021 2:29 pm
I think you are correct about VT but I just reconfig the pi to boot cli and used .profile to kick it off
There are better ways. You know that will try to start your script at every login, even over ssh?
I'm a volunteer. Take me for granted or abuse my support and I will walk away

All advice given is based on my experience. it worked for me, it may not work for you.
Need help? https://github.com/thagrol/Guides

Return to “Beginners”