chow
chow

Reputation: 484

Run shell script on reboot

Tried two methods and neither seem to be working:

crontab -e:

@reboot sleep 60;/home/linuxbox/script.sh

and created a service in /etc/systemd/system/script.service:

[Unit]
Description=a generic service to run on reboot

[Install]
WantedBy=multi-user.target

[Service]
ExecStart=/bin/bash /home/linuxbox/script.sh
Type=simple
User=linuxbox
Group=linuxbox
WorkingDirectory=/home/linuxbox

I follow that up with systemctl daemon-reload.

Not sure what is going wrong at this point -- any help is appreciated.

Upvotes: 0

Views: 1797

Answers (3)

TheDotBot
TheDotBot

Reputation: 11

Have you enabled cron?

You can enable and start it with

sudo systemctl enable cron.service   

Upvotes: 1

umläute
umläute

Reputation: 31274

Once you've created your script.service unit, you must of course enable it:

systemctl enable script.service

(This might seem obvious, but in qour question you only mention that you run systemctl daemon-reload which is not enough)

Upvotes: 0

Dillion Wang
Dillion Wang

Reputation: 361

The ExecStart command shouldn't be

/bin/bash /home/linuxbox/script.sh

but should be

/bin/bash -c "/home/linuxbox/script.sh".

Upvotes: 0

Related Questions