[英]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:我正在尝试安排一个 bash 脚本在 Windows 10 的 Windows 上的 Ubuntu 上运行 Bash。每次我编写 cron 时,我都会在终端中收到以下错误消息:
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:这是 crontab 条目的样子:
# 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.您需要将自己添加到 crontab 组中。
usermod -a -G crontab (username)
Once you have done this, you also need to make sure that cron is running.完成此操作后,您还需要确保 cron 正在运行。 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.通常这是从
start cron
开始的,但是据我所知,新贵在 WSL 上不起作用,但是sudo cron
完成这项工作。
One caveat to this is that once you close all bash windows, cron will stop running even though your computer runs.对此的一个警告是,一旦您关闭所有 bash 窗口,即使您的计算机运行,cron 也会停止运行。 However, as long as you have a bash window open and cron running, it will perform as expected.
但是,只要您打开 bash 窗口并运行 cron,它就会按预期执行。
To make sure cron is actually running you can type service cron status
.要确保 cron 实际运行,您可以键入
service cron status
。 If it isn't currently running then type service cron start
and you should be good to go.如果它当前未运行,则键入
service cron start
,您应该很高兴。
github bug上提到了这个解决方法,现在似乎找不到了!
sudo crontab -u $USER -e
try to put this powershell command in a windows task and see what happens尝试将此 powershell 命令放在 Windows 任务中,看看会发生什么
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 bash -c "command" 表示使用 linux 子系统 bash shell 运行此命令
the command is "rsync --rsync_switches /mnt/windows_drive_letter/source_dir/* rsync://rsync_daemon_address/rsync_module"命令是“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".我现在从没有管理员权限的 powershell 窗口运行它,它报告它正在“发送增量文件列表”。 the task manager reports that there is an rsync process that is doing a lot of stuff with drive d:
任务管理器报告有一个 rsync 进程正在对驱动器 d 做很多事情:
运行命令sudo service cron start
并提供密码。
Seems that your crontab does have the setgid permission set like this,似乎您的 crontab 确实具有这样设置的 setgid 权限,
-rwxr-sr-x 1 root crontab 39024 May 5 2016 /usr/bin/crontab
you should do sudo chown <username> /usr/bin/crontab
你应该做
sudo chown <username> /usr/bin/crontab
then sudo chmod g+s /usr/bin/crontab
然后
sudo chmod g+s /usr/bin/crontab
You should be root to do all this.你应该是 root 来做这一切。
WSL 目前不支持后台进程。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.