Where to put a cronjob [SOLVED]


I wanted to add a cronjob for the asterisk user. So I logged in an tried to “crontab -l” which lists all existing cronjobs. But “crontab -e” which would be the normal thing to do gives me:
/bin/sh: /bin/vi: No such file or directory
crontab: “/bin/vi” exited with status 127

Should I just install vi or is there a place in FreePBX 12 to add a cronjobs as I searched and didn’t find anything.

Thanks a lot

Just install the vi editor. If you do it correctly, vi should be accessible from anywhere.

Actually the editor that crontab will use is defined by the system variable EDITOR , so either in your .bashrc file or transiently

export EDITOR=/usr/bin/nano

or whatever, will get you comfortable,

But without the -u argument to crontab you will be using your currently logged in user, so if you are root then

crontab -u asterisk -l

will list the cronjobs for the user asterisk, similarly if you want to edit the asterisk users cron jobs , then

crontab -u asterisk -e

should get you there

(man crontab :wink: )

@dicko Thanks for explanation. I did put export EDITOR=/usr/bin/nano in my .bashrc of the asterisk user but the interesting thing was that it didn’t help because .bashrc was not sourced by default when switching to asterisk user with “sudo su - asterisk”. I also had to put “source ~/.bashrc” in .profile But your reply got me on the right track.

Also thanks for the other with to use -u option with crontab. Never heard of that trick, of course then you could easily do it with root.

Yes it’s about interactive shells, you would need to “preserve” your current environment with the -E switch for sudo.

on a new install I got the same error.

to solve I had to do this:

ln -s /usr/bin/vi /bin/vi

here is a paste of the session:

# crontab -u asterisk -e
/bin/sh: /bin/vi: No such file or directory
crontab: "/bin/vi" exited with status 127
freepbx-1  /var/spool/asterisk/backup # which vi
freepbx-1  /var/spool/asterisk/backup # ln -s /usr/bin/vi /bin/vi
freepbx-1  /var/spool/asterisk/backup # crontab -u asterisk -e
crontab: installing new crontab