Crontab Not Working with Bash on Ubuntu on Windows

35.6k views Asked by At

I am trying to schedule a bash script to run with Bash on Ubuntu on Windows in Windows 10. Every time that I to write the cron, I get the following error messages in the terminal:

crontab: installing new crontab
/var/spool/cron/: mkstemp: Permission denied
crontab: edits left in /tmp/crontab.4q0z3i/crontab

Here is what the crontab entry looks like:

# m h  dom mon dow   command
27 10 * * * /home/admin/test.sh > /home/admin/logs/test.log 2>&1   

What exactly is going on here?

9

There are 9 answers

3
arnpry On

WSL does not currently support background processes.

13
Arduino_Sentinel On

Seems that your crontab does have the setgid permission set like this,
-rwxr-sr-x 1 root crontab 39024 May 5 2016 /usr/bin/crontab

you should do sudo chown <username> /usr/bin/crontab

then sudo chmod g+s /usr/bin/crontab

You should be root to do all this.

0
Charles Plager On

It looks like this ought to start Crontab once using tmux and have it live even if you close your bash session(see here). I haven't tried this yet (but will soon).

3
Josh Correia On

To make sure cron is actually running you can type service cron status. If it isn't currently running then type service cron start and you should be good to go.

0
Abhishek Kumar On

Run the command sudo service cron start and give password.

0
steodatus On

try to put this powershell command in a windows task and see what happens

bash -c "rsync -acAXvc --delete --numeric-ids /mnt/d/no_movies/* rsync://10.66.6.66/danielle_no_movies"

bash -c "command" means run this command using the linux subsystem bash shell

the command is "rsync --rsync_switches /mnt/windows_drive_letter/source_dir/* rsync://rsync_daemon_address/rsync_module"

i just came up with it and i'm still testing so i can't promise that it will actually work.

i am running it from a powershell window with no admin privileges right now and it is reporting that it is "sending the incremental file list". the task manager reports that there is an rsync process that is doing a lot of stuff with drive d:

1
uptimeroadtrip s On

crontab does not run under windows wsl. Linux is not started with systemd

6
jeffpkamp On

You need to add yourself to the crontab group.

usermod -a -G crontab (username)

Once you have done this, you also need to make sure that cron is running. Usually this is started with start cron however upstart does not work on WSL from what I can tell, but sudo cron does the job.

One caveat to this is that once you close all bash windows, cron will stop running even though your computer runs. However, as long as you have a bash window open and cron running, it will perform as expected.

0
user7788441 On

There is workaround mentioned on the github bug for this one, can't seem to find it now!

sudo crontab -u $USER -e