Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Crontab Not Working with Bash on Ubuntu on Windows

Tags:

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?

like image 342
arnpry Avatar asked Dec 22 '16 10:12

arnpry


People also ask

Why crontab scripts are not working?

One of the most frequent causes for the crontab job not being correctly executed is that a cronjob does not run under the user's shell environment. Another reason can be – not specifying the absolute path of the commands used in the script.

Why is my crontab entry not running?

Check permissionsAnother user might have created the cron job and you may not be authorized to execute it. Note that the root must own jobs added as files in a /etc/cron. */ directory. That means that if you don't have root permissions, you might not be able to access the job.

How do I enable cron on Windows?

- Go to Start >> Control Panel >> Scheduled Tasks >> Add Scheduled Task. - Type "Moodle Cron" as the name of the task and select "Daily" as the schedule. Click "Next". - Select "12:00 AM" as the start time, perform the task "Every Day" and choose today's date as the starting date.


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

like image 161
jeffpkamp Avatar answered Sep 23 '22 13:09

jeffpkamp


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.

like image 22
Josh Correia Avatar answered Sep 23 '22 13:09

Josh Correia