I'm trying to edit my crontab, but I just can't open it!
So with my user foo, I just type:
crontab -e
Then I got:
no crontab for foo - using an empty one
nano: No such file or directory
crontab: "nano" exited with status 1
So I tried first:
export EDITOR=nano
I retried and I got exactly the same output. I also tried to set my editor to Vim with:
export EDITOR=vim
no crontab for foo - using an empty one
vim: No such file or directory
crontab: "vim" exited with status 1
But I keep getting the same output again and again. How can I open my crontab and then edit it?
Why is crontab not working in your system? Crontab might fail for a variety of reasons: The first reason is that your cron daemon might not be working for any reason, resulting in your crontab failing. There also exists a possibility that your system's environment variables are not settled correctly.
Use the env
program to pass environment variables to crontab.
sudo env EDITOR=nano crontab -e
It also works without sudo
.
I haven't found a way to do it permanently, but this works.
I was getting the exact same errors on my new EC2 instance.
no crontab for ec2-user - using an empty one
/bin/sh: /usr/bin/vi: No such file or directory
crontab: "/usr/bin/vi" exited with status 127
Vim was working fine when you open it, but crontab -e
was still not working. I then tried the solution:
export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
export EDITOR=/usr/bin/vi
which did not work, and then I typed:
which vi
alias vi='vim'
/usr/bin/vim
What did the trick for me was using Vim instead of vi on the export:
export EDITOR=/usr/bin/vim
Now my crontab -e
works.
This message is normal because you still do not have any crontab for that user:
no crontab for foo - using an empty one
Regarding the following:
nano / vim: No such file or directory
crontab: "nano" exited with status 1
It is happening because you are not defining the editor properly. To do so, you have to specify the full path of the binary:
export EDITOR=/usr/bin/nano
or
export EDITOR=/usr/bin/vi
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