3

Normal cron jobs (not using the @ symbol) run just fine.

For testing purposes, I have set up a command to be run echo "hi" > /home/kasperfred/reboot.txt which works when running from terminal, and using running as a normal cronjob with the crontab command:

* * * * * echo "hi" > /home/kasperfred/reboot.txt

But the following command doesn't work:

@reboot echo "hi" > /home/kasperfred/reboot.txt

When using sudo reboot to reboot, no reboot.txt is written, however, syslog logs the command as successfully run.

From syslog:

Jun 11 14:30:03 zeus cron[2224]: (CRON) INFO (pidfile fd = 3)
Jun 11 14:30:03 zeus cron[2224]: (CRON) INFO (Running @reboot jobs)
Jun 11 14:30:03 zeus CRON[2266]: (kasperfred) CMD (echo "hi" > /home/kasperfred/reboot.txt)

What am I doing wrong, and if this cannot be solved, what alternatives are there for running scripts at boot time?

I'm using Ubuntu Server 16.04 LTS.

Zanna
  • 70,465
  • 1
    Do you have a separate home partition (or an encrypted home directory)? Have you tried writing to somewhere like /tmp/reboot.txt instead? – steeldriver Jun 11 '17 at 13:01
  • @steeldriver it seems to work when setting the directory to /tmp even with @reboot. However, this doesn't quite explain the initial problem; namely why it doesn't launch the jupyter notebook server when it works in terminal (the notebook-dir is not encrypted) –  Jun 11 '17 at 13:29
  • 3
    Well that sounds like a whole other question - usually the issue is either that cron does not provide a suitable environment, or that other services on which the program depends are not started or are not yet ready - probably the right way to do it is to create a systemd service – steeldriver Jun 11 '17 at 13:40
  • @KasperFredenslund you set cronjob via crontab -e command or you set it in /etc/cron.d/ ? – Bahram Jul 19 '17 at 04:16
  • @Bahram I did use crontab -e –  Jul 20 '17 at 18:17
  • @KasperFredenslund Please check this answer Crontab Bugs What about root user ? is it working for root ? – Bahram Jul 21 '17 at 11:20
  • 1
    I can confirm this is a bug of Cron. Some task just doesn't work on @reboot. For example: https://askubuntu.com/a/970795/566421 – pa4080 Nov 01 '17 at 18:48

0 Answers0