I have a Python script which simply writes some text and saves it to a file
#! /usr/bin/python3
def main():
filename = \'/home/user/testHello.txt\'
From what I've discovered just now, the @reboot
syntax seems to depend on what crontab
you're editing. I found that for the system-level /etc/cron.d/
folder, entries there must have a user, just like regular time-based crons.
Thus this worked for me, on Ubuntu 14.04, to run the specified command as root on startup:
@reboot root /home/vagrant/log.sh
I managed to get @reboot working with the answer @halfer provided, but want to add an interesting abstract from man 5 crontab
... The format of a cron command is very much the V7 standard, with a number of upward-compatible extensions. Each line has five time and date fields, followed by a command, followed by a newline character ('\n'). The system crontab (/etc/crontab) uses the same format, except that the username for the command is specified after the time and date fields and before the command. The fields may be separated by spaces or tabs. The maximum permitted length for the command field is 998 characters. ...
So you might check these as well in case the job is still not running.
I've had a similar problem with a @reboot
cron job not running; in case it helps anyone else:
The problem for me is that my home directory is encrypted with eCryptfs (which is what you get if you choose to encrypt your home directory when installing Ubuntu) - broadly speaking this means that the contents of your home directory aren't available until you log in, but cron runs @reboot
jobs on reboot, not when you log in.
Mark Roberts pointed out a few things I'd done wrong.
Namely, the spaces here
MAIL = root
HOME = /
Get rid of those spaces..
Next, having Cron configuration fixed to email every minute.. instead of what I had :
*/1 * * * * /home/user/tester.py
Seems to me Lubuntu doesn't support the @Reboot Cron syntax.