The Cookie Machine - Click here to drag window

DUMMY TEXT - Real text set in assets/js/theCookieMachine.js

Views: 22,158β€…    Votes:  0β€…    βœ… Solution
Tags: server   scripts   startup   cron   autostart  
Link: πŸ” See Original Answer on Ask Ubuntu πŸ”—

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: November 24, 2022    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/:

@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:

@reboot   root    mkdir -p -v /cronjobs/demofolder
⇧ What are Kernel Version number components (w.x.yy-zzz) called? Upgrade to 16.10 causes desktop backlight flickering  β‡©