Automatically run command at boot

Hi guys,
so I want to automatically run a command at boot, but I want OSMC to wait with the command until everything is done. like you already are in OSMC and the internet connection has been established.
I want to run the command pppd pty "pptp IP_OF_SERVER --nolaunchpppd" file /etc/ppp/options.pptp user USERNAME password PASSWORD at boot, like I said, after everything is done.

I’m not a linux guru, and I tried putting it in /etc/rc.local
this is how my /etc/rc.local looks like:

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
pppd pty "pptp IP_OF_SERVER --nolaunchpppd" file /etc/ppp/options.pptp user USERNAME password PASSWORD
exit 0

I have tested the command, and by itself, it works

I’m not a linux guru either.

What I would do is add the command as a cron job with a delay. So, access crontab with sudo crontab -e. At the end of the file add the line:
@reboot sleep 60 && your_command
This command runs 60 seconds after every reboot. Hopefully 60 seconds is long enough to have the internet connection established, if not just increase it further.

Thanks for your reply, unfortunately I get this error:
sudo: crontab: command not found

Install crontab via App store

I’ve installed crontab, but it does not seem to run the cronjobs.
running ps ax | grep cron shows:
235 ? Ss 0:00 /usr/sbin/cron -f

the file that sudo nano crontab -e shows up looks like this:

# m h dom mon dov command
@reboot sleep 120 && sudo pppd pty "pptp SERVER_IP --nolaunchpppd" file /etc/ppp/options.pptp user USERNAME password PASSWORD

If you run crontab -e as root (which you are by using sudo) then you are editing root’s crontab. As such you do not need to put sudo in your crontab entry.

It should be:

sudo crontab -e

not sudo nano crontab -e, by the way.

Also always provide the full path to your executable in crontab files - for example:

@reboot sleep 120 && /path/to/pppd pty "pptp SERVER_IP --nolaunchpppd" file /etc/ppp/options.pptp user USERNAME password PASSWORD

ah, so thats why it would work.
tho I’ve got it working now thanks to some real heavy googling and trial-error.

I put the command in /etc/init.d/start-vpn which looks like this:

#!/bin/bash
echo "Starting the VPN Connection, hang on tight!"
sudo pppd pty "pptp SERVER_IP --nolaunchpppd" file /etc/ppp/options.pptp user USERNAME password PASSWORD

and then call the script in /etc/rc.local:

/etc/init.d/start-vpn
exit 0

then to keep the VPN as alive as I can, I run a cronjob every 10 minutes:
*/10 * * * * /home/check-vpn

where /home/check-vpn contains this script:

EXIST=`ip route show SERVERIP | wc -l`
if [ $EXIST -eq 0 ]
then
    /etc/init.d/start-vpn
fi

Thanks guys for your help :slightly_smiling: