per-user scheduling

will be run with user-previliges.

uname -a; # tested with
Linux debian 3.16.0-4-686-pae #1 SMP Debian 3.16.43-2 (2017-04-30) i686 GNU/Linux

vim /scripts/cron_test.sh; # lets create a test-script

wall "crontab has run a job" at `date +%Y-%m-%d:%H:%M:%S`; # script content

ESC :wq # save and quit vim

date
Thu May 18 14:52:16 CEST 2017

crontab -e; # edit per-user time-scheduling config file

# minute
# |    hour
# |    |     day of month
# |    |     |     month
# |    |     |     |   day of week (0=Sun-day,1=Mon-day,2=Tue-sday,3=Wed-nesday,4=Thu-rsday,5=Fri-day,6=Sat-urday)
# |    |     |     |   |      command
 11   15    18     5   *      /scripts/cron_test.sh # will run yearly on 20XX.05.18th at 15:11
 11   15    18     5   Thu    /scripts/cron_test.sh # will run yearly on 20XX.05.18th at 15:11 but also every week on Thurdsay at 15:11
 11   15     *     *   1-5    /scripts/cron_test.sh # will run daily from Monday-Friday at 15:11
 11   15-18  *     *   1-5    /scripts/cron_test.sh # will run start script every hour from 15.00-18.00 (4x times) from Monday-Friday
  *   *      *     *   *      /scripts/cron_test.sh # will run every minute
  */5 *      *     *   *      /scripts/cron_test.sh # will run every five minute

# worked flawlessly

# if there was an error parsing your crontab file you get:
errors in crontab file, can't install.
Do you want to retry the same edit? (y/n) y

system-wide crontab

will be run by root

vim /etc/crontab

# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m h dom mon dow user  command
17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly
25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6    * * 7   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6    1 * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
#

cron folders

if computer is powered-off – and the time a process should start has passed – the scripts in these folders will start – when the computer is powered on the next possible time.

ll /etc/|grep cron
drwxr-xr-x 2 root root   4.0K May 17 16:57 cron.d
drwxr-xr-x 2 root root   4.0K May 17 16:57 cron.daily
drwxr-xr-x 2 root root   4.0K Apr 24 12:49 cron.hourly
drwxr-xr-x 2 root root   4.0K Apr 24 12:49 cron.monthly
-rw-r--r-- 1 root root    722 Jun  7  2015 crontab
drwxr-xr-x 2 root root   4.0K Apr 24 12:50 cron.weekly

ll /etc/cron.hourly
(empty)

ll /etc/cron.daily
total 68K
-rwxr-xr-x 1 root root  625 Feb 25 11:05 apache2
-rwxr-xr-x 1 root root  15K Dec 11 10:50 apt
-rwxr-xr-x 1 root root  314 Nov  8  2014 aptitude
-rwxr-xr-x 1 root root  355 Oct 17  2014 bsdmainutils
-rwxr-xr-x 1 root root 1.6K May  3  2016 dpkg
-rwxr-xr-x 1 root root 4.1K Jan  7 04:22 exim4-base
-rwxr-xr-x 1 root root   89 Nov  8  2014 logrotate
-rwxr-xr-x 1 root root 1.3K Dec 31  2014 man-db
-rwxr-xr-x 1 root root  435 Jun 13  2013 mlocate
-rwxr-xr-x 1 root root 1.1K Jul 22  2016 ntp
-rwxr-xr-x 1 root root  249 Nov 19  2015 passwd
-rwxr-xr-x 1 root root  349 May 24  2016 quota
-rwxr-xr-x 1 root root  383 Apr  1 21:15 samba

ll /etc/cron.weekly
total 4.0K
-rwxr-xr-x 1 root root 771 Dec 31  2014 man-db

ll /etc/cron.monthly
(empty)

ll /etc/cron.d
total 4.0K
-rw-r--r-- 1 root root 661 Feb  8 11:15 php5

manpages:

admin