Cron does not execute the system crontab.
Install and configure crontab:
/etc/nixos/configuration
services.cron.enable = true;
services.cron.systemCronJobs = [ "* * * * * wall CRON WORKS"];
No message is received after 1 minute.
I don't think wall is a good choice here. Would you mind trying to execute date >>/tmp/cron-is-alive instead?
I tried that beforehand. It did not work as well. Not even touch worked. The wall test was to check, whether there were some weird access right issues.
Can you verify if the cron service is running? (systemctl status cron)
if i had to guess you hit same problem with cron i did. cron isnt on the write path. I did an echo ${PATH} on my cli and copied that into my cron file as PATH=result of my echo and it started to function correctly.
Same issue here.
Follow the instructions here to do a Minimal Install (For Servers)
{ config, pkgs, ...} :
{
boot.loader.grub.device = "/dev/sda";
# Enable virtualbox guest additions
virtualisation.virtualbox.guest.enable = true;
# Enable the sshd daemon so you can ssh
# into the
services.openssh.enable = true;
fileSystems = [
{ mountPoint = "/";
label = "nixos";
}
];
}
install, shutdown, remove .iso installer, boot the server.
Then change the configuration into:
{ config, pkgs, ...} :
{
boot.loader.grub.device = "/dev/sda";
# Enable virtualbox guest additions
virtualisation.virtualbox.guest.enable = true;
# Enable the sshd daemon so you can ssh
# into the
services.openssh.enable = true;
services.cron.enable = true;
services.cron.systemCronJobs = [
"* * * * * echo echo Hello world > /tmp/cronout"
];
fileSystems = [
{ mountPoint = "/";
label = "nixos";
}
];
}
apply the new config
nixos-rebuild switch
reboot
Wait a few minutes after the reboot.
[root@nixos:/]# systemctl status cron
● cron.service - Cron Daemon
Loaded: loaded (/nix/store/pb8nbbfl5khaql4qp5k04ndks02f0fxq-unit-cron.service/cron.service; bad; vendor preset: enabled)
Active: active (running) since Sun 2016-11-13 02:25:06 UTC; 1min 37s left
Process: 505 ExecStartPre=/nix/store/8xabcn2f9pq9n7lxvfyffmfq17dzpibg-unit-script/bin/cron-pre-start (code=exited, status=0/SUCCESS)
Main PID: 544 (cron)
Tasks: 1 (limit: 4915)
CGroup: /system.slice/cron.service
└─544 /nix/store/da425yixg567w33knnd8w6mxzkc71kzf-cron-4.1/bin/cron -n
Nov 13 02:25:06 nixos systemd[1]: Starting Cron Daemon...
Nov 13 02:25:06 nixos systemd[1]: Started Cron Daemon.
[root@nixos:/]# cat /etc/crontab
SHELL=/nix/store/28wl3f34vfjpw0y5809bgr6382wqdscf-bash-4.3-p48/bin/bash
PATH=/nix/store/q2caan69wn30vd5bmlgicvvql0rpfr5c-system-path/bin:/nix/store/q2caan69wn30vd5bmlgicvvql0rpfr5c-system-path/sbin
NIX_CONF_DIR=/etc/nix
* * * * * echo echo Hello world > /tmp/cronout
[root@nixos:/]# ls /tmp/
ca-cert.crt root
@shlevy @rbvermaa are the last to touch the cron service so maybe they can help.
Hello
I have similar problem.
In /etc/crontab you must specify the user executing the command, echo is not a valid user.
It works with this line : * * * * * root echo Hello world > /tmp/cronout
@mmai adding root saved my day, thanks!
Looks like the issue was caused by an incorrect configuration provided in services.cron.systemCronJobs. Unless we make that option into an attrset, there does not seem to be much to do here. I suggest closing the issue.
@d4g: Can you confirm?
Hello, thanks for the feedback.
I can confirm, that adding the user fixes the issue.
What still seems to be an issue is adding the correct path for requiered packages in system cron jobs.
It is a possibility to use systemd.timers instead.
Thank you for resolving the issue.
Question for nixos ppl, is this enough to schedule cron jobs:
# Enable cron service
services.cron = {
enable = true;
systemCronJobs = [
"*/30 * * * * root date >> /tmp/cron.log"
];
};
I put the above in /etc/nixos/configuration.nix, will cron jobs start happening every 30 minutes now?
Or do I need to do more?
@ORESoftware - it worked for me.
However for most of other commands you'll need correct PATH for them. It is explained in https://nixos.wiki/wiki/Cron#Loading_environment
For my script it was as follows:
services.cron = {
enable = true;
systemCronJobs = [
"*/10 * * * * root . /etc/profile; bash my_script.sh"
];
};