Home » crontab’s @reboot only works for root?

crontab’s @reboot only works for root?


This can be a bit of a confusing topic because there are different implementations of cron. Also there were several bugs that broke this feature, and there are also some use cases where it simply won’t work, specifically if you do a shutdown/boot vs. a reboot.


datapoint #1

One such bug in Debian is covered here, titled: cron: @reboot jobs are not run. This seems to have made it’s way into Ubuntu as well, which I can’t confirm directly.

datapoint #2

Evidence of the bug in Ubuntu would seem to be confirmed here in this SO Q&A titled: @reboot cronjob not executing.


comment #1: …. 3) your version of crond may not support @reboot are you using vix’s crond? … show results of crontab -l -u user

comment #2: … It might be a good idea to set it up as an init script instead of relying on a specific version of cron’s @reboot.

comment #3: … @MarkRoberts removed the reboot and modified the 1 * * * * , to */1 * * * * , problem is solved! Where do I send the rep pts Mark? Thank you!

The accepted answer in that Q&A also had this comment:

Seems to me Lubuntu doesn’t support the @Reboot Cron syntax.

Additional evidence

datapoint #3

As additional evidence there was this thread that someone was attempting the very same thing and getting frustrated that it didn’t work. It’s titled: Thread: Cron – @reboot jobs not working.


Re: Cron – @reboot jobs not working

Quote Originally Posted by ceallred View Post
This is killing me… Tried the wrapper script. Running manually generates the log file… rebooting and the job doesn’t run or create log file.

Syslog shows that CRON ran the job… but again, no output and the process isn’t running.
Jul 15 20:07:45 RavenWing cron[1026]: (CRON) INFO (Running @reboot jobs)
Jul 15 20:07:45 RavenWing CRON[1053]: (ceallred) CMD (/home/ceallred/Scripts/run_spideroak.sh > /home/ceallred/Scripts/SpiderOak.log 2>&1 &)

It’s seems like cron doesn’t like the @reboot command…. Any other ideas?

Okay… Partially solved. I’ll mark this one as solved and start a new thread with the new issue…..

I think the answer was my encrypted home directory wasn’t mounted when CRON was trying to run the script (stored in /home/username/scripts). Moved to /usr/scripts and the job runs as expected.

So now it appears to be a spideroak issue. Process starts, but by the time the boot process is finished, it’s gone. I’m guessing a crash for some reason…. New thread to ask about that.

Thanks for all the help!

Once this above user figured out his issue he was able to get @reboot working out of the crontab entry of a user.

I’m not entirely sure what version of cron is used on Ubuntu, but this would seem to indicate that user’s can use @reboot too, or that the bug was fixed at some point in subsequent versions of cron.

datapoint #4

I tested on CentOS 6 the following and it worked.


$ crontab -l
@reboot echo "hi" > /home/sam/reboot.txt 2>&1

I then rebooted the system.

$ sudo reboot

After the reboot.

$ cat reboot.txt 

Take aways

  1. This feature does seem to be supported for both system and user crontab entries.
  2. You have to make sure that it’s supported/working in your particular distro and/or version of the cron package.

For more on how the actual mechanism works for @reboot I did come across this blog post which discusses the innards. It’s titled: @reboot – explaining simple cron magic.

Debugging crond

You can turn up the verbosity of crond by adding the following to this configuration file on RHEL/CentOS/Fedora based distros.

$ more crond 
# Settings for the CRON daemon.
# CRONDARGS= :  any extra command-line startup arguments for crond

The valid levels are 0, 1, or 2. To revert this file back to it’s default logging level simply remove the "-L 2" when you’re done debugging the situation.

I found out that on my Ubuntu machine, I do not have access to dns services, yet, at @reboot time. This prevented me from mounting remote volumes. This corny, yet simple, solution worked:

@reboot sleep 60 && /home/me/bin/mount.sh 2>&1 >> /home/me/reboot.log

(in root cron; last parts only for debugging)

I have mac osx as well and I had same issue where my script were not running. but When i fixed my script to like

@reboot   cd /home/me/  && sh myscript.sh

it worked fine for me. make sure to make your shell file to be executable by running the command

chmod +x myscript.sh

Related Solutions

Joining bash arguments into single string with spaces

[*] I believe that this does what you want. It will put all the arguments in one string, separated by spaces, with single quotes around all: str="'$*'" $* produces all the scripts arguments separated by the first character of $IFS which, by default, is a space....

AddTransient, AddScoped and AddSingleton Services Differences

TL;DR Transient objects are always different; a new instance is provided to every controller and every service. Scoped objects are the same within a request, but different across different requests. Singleton objects are the same for every object and every...

How to download package not install it with apt-get command?

Use --download-only: sudo apt-get install --download-only pppoe This will download pppoe and any dependencies you need, and place them in /var/cache/apt/archives. That way a subsequent apt-get install pppoe will be able to complete without any extra downloads....

What defines the maximum size for a command single argument?

Answers Definitely not a bug. The parameter which defines the maximum size for one argument is MAX_ARG_STRLEN. There is no documentation for this parameter other than the comments in binfmts.h: /* * These are the maximum length and maximum number of strings...

Bulk rename, change prefix

I'd say the simplest it to just use the rename command which is common on many Linux distributions. There are two common versions of this command so check its man page to find which one you have: ## rename from Perl (common in Debian systems -- Ubuntu, Mint,...

Output from ls has newlines but displays on a single line. Why?

When you pipe the output, ls acts differently. This fact is hidden away in the info documentation: If standard output is a terminal, the output is in columns (sorted vertically) and control characters are output as question marks; otherwise, the output is...

mv: Move file only if destination does not exist

mv -vn file1 file2. This command will do what you want. You can skip -v if you want. -v makes it verbose - mv will tell you that it moved file if it moves it(useful, since there is possibility that file will not be moved) -n moves only if file2 does not exist....

Is it possible to store and query JSON in SQLite?

SQLite 3.9 introduced a new extension (JSON1) that allows you to easily work with JSON data . Also, it introduced support for indexes on expressions, which (in my understanding) should allow you to define indexes on your JSON data as well. PostgreSQL has some...

Combining tail && journalctl

You could use: journalctl -u service-name -f -f, --follow Show only the most recent journal entries, and continuously print new entries as they are appended to the journal. Here I've added "service-name" to distinguish this answer from others; you substitute...

how can shellshock be exploited over SSH?

One example where this can be exploited is on servers with an authorized_keys forced command. When adding an entry to ~/.ssh/authorized_keys, you can prefix the line with command="foo" to force foo to be run any time that ssh public key is used. With this...

Why doesn’t the tilde (~) expand inside double quotes?

The reason, because inside double quotes, tilde ~ has no special meaning, it's treated as literal. POSIX defines Double-Quotes as: Enclosing characters in double-quotes ( "" ) shall preserve the literal value of all characters within the double-quotes, with the...

What is GNU Info for?

GNU Info was designed to offer documentation that was comprehensive, hyperlinked, and possible to output to multiple formats. Man pages were available, and they were great at providing printed output. However, they were designed such that each man page had a...

Set systemd service to execute after fstab mount

a CIFS network location is mounted via /etc/fstab to /mnt/ on boot-up. No, it is not. Get this right, and the rest falls into place naturally. The mount is handled by a (generated) systemd mount unit that will be named something like mnt-wibble.mount. You can...

Merge two video clips into one, placing them next to each other

To be honest, using the accepted answer resulted in a lot of dropped frames for me. However, using the hstack filter_complex produced perfectly fluid output: ffmpeg -i left.mp4 -i right.mp4 -filter_complex hstack output.mp4 ffmpeg -i input1.mp4 -i input2.mp4...

How portable are /dev/stdin, /dev/stdout and /dev/stderr?

It's been available on Linux back into its prehistory. It is not POSIX, although many actual shells (including AT&T ksh and bash) will simulate it if it's not present in the OS; note that this simulation only works at the shell level (i.e. redirection or...

How can I increase the number of inodes in an ext4 filesystem?

It seems that you have a lot more files than normal expectation. I don't know whether there is a solution to change the inode table size dynamically. I'm afraid that you need to back-up your data, and create new filesystem, and restore your data. To create new...

Why doesn’t cp have a progress bar like wget?

The tradition in unix tools is to display messages only if something goes wrong. I think this is both for design and practical reasons. The design is intended to make it obvious when something goes wrong: you get an error message, and it's not drowned in...