Crontab not working with Bash on Ubuntu on Windows

I am trying to schedule a bash script to run from bash on Ubuntu on Windows on Windows 10. Each time I write 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 crontab looks like:

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

What exactly is going on here?

+6
source share
5 answers

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 cron is running. This usually starts with start cron , however the upstart does not work on WSL from what I can say, but sudo cron does the job.

One caveat is that after closing all windows, bash cron will stop working even if your computer is running. However, while you open the bash window and run cron, it will work as expected.

+14
source

There is a workaround mentioned in the github error for this, it seems it cannot find it now!

 sudo crontab -u $USER -e 
+2
source

try putting 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 running this command using the linux subsystem bash shell

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

I just came up with this and I'm still testing, so I can’t promise that it will really work.

I run it from the powershell window without any administrator rights, and it reports that it "sends an incremental list of files." task manager reports that there is an rsync process that does a lot of things with d:

+1
source

It seems your crontab has setgid permission set similar to this,
-rwxr-sr-x 1 root crontab 39024 May 5 2016 /usr/bin/crontab

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

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

You must be root to do all this.

0
source

WSL does not currently support background processes.

0
source

Source: https://habr.com/ru/post/1013418/


All Articles