Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't edit crontab

Tags:

cron

archlinux

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?

like image 870
Hito Avatar asked Feb 18 '14 09:02

Hito


People also ask

Why crontab is not working?

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.


3 Answers

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.

like image 175
Simao Gomes Viana Avatar answered Sep 22 '22 07:09

Simao Gomes Viana


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.

like image 40
Sean Avatar answered Sep 22 '22 07:09

Sean


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
like image 25
fedorqui 'SO stop harming' Avatar answered Sep 20 '22 07:09

fedorqui 'SO stop harming'