简体   繁体   中英

Crontab Not Working with Bash on Ubuntu on Windows

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?

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.

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.

github bug上提到了这个解决方法,现在似乎找不到了!

sudo crontab -u $USER -e

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:

运行命令sudo service cron start并提供密码。

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.

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).

WSL 目前不支持后台进程。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM