VE3WGW
Posts: 2
Joined: Thu Oct 17, 2019 12:06 pm

Auto run a program on startup in terminal

Thu Oct 17, 2019 10:59 pm

Hi. VE3WGW here Graham..
I am into ham radio I like modifying commercial equipment to operate on the ham bands.

I have a piece of equipment that has 2 PLL's in it. The " original " processors are
set up in a way that it cannot be changed , BUT... I have a Pi Zero that does it quite nicely.
Code for the Pi was written in C a few years ago. The gentleman who wrote the code has passed...
There is no info on the code, but it compiled and works as it should bypassing the internal processors and programming the PLL"s as needed..
As this is for a repeater which is not close it has to run automatically on a power fail and return.
Manually I can type the lines necessary and up it comes.
What I need is help... I am new to the Pi and I can't find a solution ..
The program works in the terminal.
What I have done so far is get the Pi to boot into terminal mode.
I then have to type " sudo su " to get Superuser mode
next cd Rpi to the directory where it is..
Then enter rpi_pll -r 902.4125 -t 927.4125
It does its' thing and all works.
I then enter halt and the Pi goes to sleep.
I cannot enter shutdown as that changes the states of the GPIO and the PLL's go nuts.

What I need the help with is How do I set the Pi up to automatically run the program and then halt?
Any help would be greatly appreciated.

Graham

Andyroo

Re: Auto run a program on startup in terminal

Fri Oct 18, 2019 8:28 am

You could try entering the command into cron along these lines:

Code: Select all

@reboot sleep 10 && sudo /home/pi/Rpi/rpi_pll -r 902.4125 -t 927.4125 && sudo halt
Cron is documented very well as a Google will show but a basic intro is here

You could also try running this as the root user and miss out the sudo like

Code: Select all

@reboot sleep 10 && /home/pi/Rpi/rpi_pll -r 902.4125 -t 927.4125 && halt
This does assume you do not need to change into the directory to run it - if so you will need a little script file to do that.

Then to run this, connect up the PLL, power on the Pi and off it goes.

Note: This will run every time the Pi is rebooted - may not be the best idea if you want to use the Pi for other things :lol:

VE3WGW
Posts: 2
Joined: Thu Oct 17, 2019 12:06 pm

Re: Auto run a program on startup in terminal

Fri Oct 18, 2019 4:29 pm

Unfortunately that did not work..
Back to the drawing board..

NotRequired
Posts: 196
Joined: Sat Apr 29, 2017 10:36 am
Location: Denmark

Re: Auto run a program on startup in terminal

Fri Oct 18, 2019 5:24 pm

Create a shell script named "/home/pi/startup_commands.sh" and let it contain:

Code: Select all

#!/bin/sh

/home/pi/Rpi/rpi_all -r 902.4125 -t 927.4125
halt
Make sure to enable the execute attribute for the script with: "chmod +x /home/pi/startup_commands.sh". Now add the following line to "/etc/rc.local":

Code: Select all

/home/pi/startup_commands.sh &
And see how it goes :)

https://www.raspberrypi.org/documentati ... c-local.md
Please do not ask questions in private messages, they will not help others.

Andyroo

Re: Auto run a program on startup in terminal

Fri Oct 18, 2019 7:05 pm

You could also add the change directory to the script as well :lol:

Return to “General discussion”