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:


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 
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.


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)

| improve this answer | |
  • 1
    Great solution, unless you want to be sure that a specific service has been started. For example docker – michaelbn Jan 29 '18 at 14:10
  • sshuttle required to use systemd, cron did not work – yourstruly Jul 15 '18 at 12:47
  • In this answer, is root the user to run the script i assume? – ZillaYT Apr 6 at 17:17
  • @ZillaYT: see man 5 crontab – Jaleks Apr 8 at 12:28

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:




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.

| improve this answer | |

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