-2

I have a bash script which is in this directory:

/home/pi/darkCove/radio/start.sh

It basically transmitts an FM signal. Here is the code:

#!/bin/bash

sudo ./pi_fm_rds -freq 87.5 -audio pulses.wav -ps 'DarkCove' -rt 'DarkCove FM - Crypto Prices & News' -pi 1234

I Know that this question has already been asked but I can't seem top make anything work. I need this program to run in this directory and It needs to stay open. Please answer the question and don't just say "That's illegal." I know what I'm doing and im conscious that this is illegal but please, just don't answer this question if this is what you are going to write.

wnetMC
  • 105
  • 1
  • 3
    I’m voting to close this question because it is illegal – joan Jan 05 '21 at 21:42
  • 3
    Admitting to engaging illegal activity is not illegal, generally speaking discussing how to do something that may be illegal in the UK or the USA or China or Russia or Luxembourg or all of the above is NOT illegal. If the CIA or MI6 or FCC or whoever wants to monitor this board in order to uncover illegal activity by users, including the wanton and maniacal misuse of radio signals, that's fine, but there is nothing illegal going on here. Please see: https://meta.stackexchange.com/questions/358963/tos-and-ill-quasi-legal-activity – goldilocks Jan 05 '21 at 23:18
  • Does this answer your question? Run bash script on startup – Dmitry Grigoryev Jan 07 '21 at 09:09
  • @joan Low-power FM transmitters are legal in most parts of the world. That's how MP3 players for old cars work. – Dmitry Grigoryev Jan 07 '21 at 09:13

2 Answers2

1

Many scripts that need to be run at startup can be started by adding it to /etc/rc.local. You can check the linux documentation to see how rc.local works. Since it requires elevated privileges, use sudo to run the command. Be careful to add a & at the end of the statement to allow startup to occur normally.

Seamus
  • 21,900
  • 3
  • 33
  • 70
Adi
  • 44
  • 4
  • I already tried and this does not work – wnetMC Jan 05 '21 at 21:08
  • 1
    Just saying it does not work is unhelpful, why does it not work? Are there error statements? Did you try just calling a separate file and looking at its output? Did you try running rc.local manually? There's no reason for it to not work – Adi Jan 05 '21 at 21:16
  • I am able to run rc.local but nothing pops up at startup. It is an ongoing nprocess which can't be stopped. If it works, will a terminal window pop up and run my command at startup? I don't get anything. – wnetMC Jan 06 '21 at 01:25
  • 1
    I'm sorry, but rc.local is deprecated - it shouldn't be used unless you know how to avoid the pitfalls. – Seamus Jan 06 '21 at 07:17
  • Please take note that using /etc/rc.local has limitations due to Compatibility with SysV. We have seen many problems here on this site using it. Following the recommendation of the developers from systemd you should avoid using it. – Ingo Jan 06 '21 at 09:57
  • That's helpful, I did not know about the limitations of rc.local, i was of the idea that the difference between the 2 was purely aesthetic, cron being used for system updates and rc.local being used for one time startup configurations – Adi Jan 06 '21 at 14:24
  • I think you've got the point, and I've removed my downvote. – Seamus Jan 07 '21 at 08:02
1

You might try using root's crontab. Something like this:

$ sudo crontab

This will open an editor for root's crontab. Enter the following (or something similar) in the editor, save it, close the editor & reboot. Don't know what you mean by "It needs to stay open.", but you can edit your question if you wish to add additional details.

@reboot (sleep 30; /home/pi/darkCove/radio/start.sh) >> /home/pi/logfile.txt 2>&1

The sleep 30 command waits 30 seconds before starting your script. No idea whether this is needed or not, but you can reduce it or delete it if not needed. The redirect after calling your script is to put any stderr output in a file. Again, you may delete this if you don't want or need it.

Oh - one other thing: Make sure your script is marked as executable (chmod).

Seamus
  • 21,900
  • 3
  • 33
  • 70