On my new Ubuntu system I tried to start a Bash script automatically on system start up.
I found a lot of posts and how-to's about it. so I tried to make it via Crontab:
- run
crontab -e - add
@reboot /cronjobs/demo.sh >> /cronjobs/cronLogs/demo.output - set execution permission to script with
sudo chmod +x /cronjobs/demo.sh - reboot system
The output was created, but the script will not execute.
So I tried another solution with rc.local file:
- run
sudo vi /etc/rc.local - added
/cronjobs/demo.sh || exit 1 - reboot system
But my script doesn't run.
So I read that for reboot the script must be in /etc/rc0.d/. So I tried this:
- move the script with
mv /cronjobs/demo.sh /etc/rc0.d/K99_demo.sh - check permissions (all seems to be ok)
- reboot system
Same thing - script will not be executed.
So, what's my error? Why my script can't be executed?
I can execute my script if I run ./demo.sh after i switched to the folder with cd /cronjobs . The script is a demo-file which simply creates a folder:
#!/bin/sh echo demo output mkdir /cronjobs/demofolder
Edited: Replaced paths and filenames; added full content of demo.sh file
log.outputwas created after system startup - with my echo i typed inscript.shto log something. But the scriptscript.shwould not be executed (means that thedemofolderwasn't created). – devKyrios Oct 30 '16 at 16:36