0

I am trying to run the below command to run automatically on startup

upnpc -a `ifconfig eth0 | grep "inet addr" | cut -d : -f 2 | cut -d " " -f 1` 80 5900 TCP

I have added this command in /home/pi/.config/lxsession/LXDE-pi/autostart as I wanted it to run for the user pi only.

but it is not working, as I can see the port forward doesnt appear in router page virtual servers , however if I run the above command manually from the shell of pi , it works and forwarded port appears in router page.

I followed this discussion regarding where to put.

  • If you are running a recent version of Raspbian there is an option in raspi-config to wait for network at boot. It slows the boot time very slightly. You can use the following command to get the menu sudo raspi-config. Having said that are you sure that is why it is failing? – Steve Robillard Sep 3 '16 at 8:57
  • well strange but I hardcoded internal ip of my server rather than greping and it worked. – Ciasto piekarz Sep 3 '16 at 9:53
1

You can make a systemd service for your program and enable it via systemctl.

First, create a file /etc/systemd/system/<name>.service on the Pi. (Be sure to replace <name> with a actual service name.)

sudo touch /etc/systemd/system/<name>.service

Write in this file with your favorite text editor (nano, etc):

[Unit]
Description=blah service
After=network.target

[Service]
Type=oneshot
User=pi
ExecStart=yourcommand


[Install]
WantedBy=multi-user.target

Replace yourcommand with the command you want to run. Then save the file and close the text editor.

Next, reload the daemon to make systemd recognize your service:

sudo systemctl daemon-reload

Then, we can make it run on boot now:

sudo systemctl enable <name>

(Again, make sure to replace <name> with the name of your service.)

Enjoy your start-on-boot command!

EDIT: didn't realize this post was that old actually. but anyways, either mark a answer as correct or state your solution in a answer and mark that so it doesn't show up on the front page

| improve this answer | |
  • Systemd is loads better than init.rc scripts. Thanks for this guide. – acer Jan 4 at 19:16
0

If you want to run the command as pi do su -l pi -c "put command inside quotation marks" instead of just doing it normally. So, for example, su -l pi -c "upnpc -a ifconfig eth0 | grep "inet addr" | cut -d : -f 2 | cut -d " " -f 1 80 5900 TCP".

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.