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?
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.
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.
- 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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With