Views:
23,139β
Votes: 0β
β
Solution
Tags:
server
scripts
startup
cron
autostart
Link:
π See Original Answer on Ask Ubuntu β§ π
URL:
https://askubuntu.com/q/843328
Title:
Start script on system startup (Ubuntu 16.04.1)
ID:
/2016/10/29/Start-script-on-system-startup-_Ubuntu-16.04.1_
Created:
October 29, 2016
Edited: June 12, 2020
Upload:
September 15, 2024
Layout: post
TOC:
false
Navigation: false
Copy to clipboard: false
The easiest solution is using sudo powers create a file like this in /etc/cron.d/
:
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
@reboot root mkdir /cronjobs
@reboot root sleep 10
@reboot root mkdir /cronjobs/demofolder
This avoids the use of a script file altogether and works for all users regardless of their home directory name, ie /home/steve, /home/mary, etc.
Edit - Add sleep 10
For whatever reason cron is working too fast, or kernel is working too slow when making directories. An extra line sleep 10
was necessary between the two mkdir
lines.
You may not need 10 seconds in between the two make directory commands but 10 works on my system with an SSD.
Edit 2 - Make full directory path in one command
As per comments below a simpler method is to use:
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
@reboot root mkdir -p -v /cronjobs/demofolder
-p
(long version--parents
) tellsmkdir
to automatically create all directory parent levels if they donβt exist.-v
(long version--verbose
) tellsmkdir
to print the names of all directories created.