I did a lot of research on this and I saw a lot of ways on how to do this. However, none of it seems working for me. For example, I did something like this:

~/.config/upstart/text.config

I created a .config file under the directory mentioned above and wrote the following command (testScript.sh below is the script that i wanted to run) :

start on startup 
task 
exec /path/to/testScript.sh

Another way that i tried, I wrote something like this in rc.local file:

sudo -H /etc/init.d/testScript.sh start

And I put my testScript.sh in init.d. Both of these ways didn't work for me. The system didn't give me any errors or remarks. Did i make a mistake somewhere or is there another way to do this? So that my script execute automatically on the startup of the system.

share|improve this question

closed as off-topic by jasonwryan, Jeff Schaller, phk, GAD3R, Satō Katsura Jun 5 '17 at 14:42

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question has been posted on multiple sites. Cross-posting is strongly discouraged; see the help center and community FAQ for more information." – Jeff Schaller, phk, Satō Katsura

    
Which release of Ubuntu? – Deathgrip Jun 5 '17 at 7:41
    
If you execute update-rc.d testScript.sh enable the proper links will be created in the various /etc/rc?.d directories. Read up on the boot process. A good place to start is wiki.debian.org/LSBInitScripts. Although newer releases of Linux systems also use systemd and Upstart. – Deathgrip Jun 5 '17 at 7:47
    
Cross-posted: stackoverflow.com/q/44360295/4957508 – Jeff Schaller Jun 5 '17 at 9:45
    
crontab it maybe? – Fl.pf. Jun 7 '17 at 8:43

Lets Do some check First,

1: Check weather you script is running properly on os.(means is it not getting any error or getting stuck somewhere).

2: you need to create a systemd startup script Eg. testScript.service and place it into /etc/systemd/system/ directory. You can add script as the example of such systemd startup script below:

[Unit]
After=mysql.service

[Service]
ExecStart=/usr/local/bin/testScript.sh

[Install]
WantedBy=default.target

Copy script to /usr path and Before rebooting system you need to make your script executable:

cp /path/to/testScript.sh /usr/local/bin/testScript.sh
chmod 744 /usr/local/bin/testScript.sh

3: Next, install systemd service unit and enable it so it will be executed at the boot time:

chmod 664 /etc/systemd/system/testScript.service
systemctl daemon-reload
systemctl enable testScript.service
Created symlink from /etc/systemd/system/default.target.wants/testScript-sp

Hope this works well , i have tested in my system and working fine.. Still you have on mo option putting it in crond with Add the line @reboot.

share|improve this answer

Why not just use plain cron for it? Edit /etc/crontab as superuser and add a line

@reboot     root    /path/to/testScript.sh

that should do the trick without any more hassle. (see man 5 crontab for more cron options)

share|improve this answer

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