"crontab -e" works, "sudo crontab -e" does not!

I created an rsync-script, which is frequently running for backing up files and basically everything is fine.
The problem is, that there are some files, which can’t be copied/configured without root permissions.

At the moment my scripts runs as result of a command in
crontab -e

What i now wanted to do is to shift this command to the
sudo crontab -e
or
crontab -e -u root

The problem is, that when i enter crontab as sudo, i dont get to edit the crontab.
I end up with this weird window, where i can’t even find a shortcut to exit again → I have to kill the whole terminal window

Does anyone know what im doing wrong or whats missing?
Ive already been searching for a solution but did not find anyone with exactly the same issue …

Output of my console looks like this:

~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
"/tmp/crontab.3FJ2fm" 0 lines, 0 characters

Why make it hard on yourself? timeshift can do all of that too. :wink:

You won’t have write access with that. That command is to be used by the root user only.

That weird window is the vi or vim editor, which is the default editor for crontabs if no other editor has been specified for that user account by way of the $EDITOR variable.

One exits vi by pressing Esc, followed by typing the following (if one does not want to save the file)… :arrow_down:

:q!

… followed by pressing Return/Enter


What you could try is the following… :arrow_down:

1. Create a systemd timer instead of a crontab; or

2. Use su instead of sudo. :arrow_down:

sudo su -
EDITOR=nano crontab -e
3 Likes

First of all thank you very much!

Why make it hard on yourself? timeshift can do all of that too. :wink:

Im already using timeshift, and want do “double-backup” these files
→ Im pretty sure, that there is a better way to implement this but i dont have a RAID-Nas or something like this and wanted to keep it simple :grimacing: → Create a redundant version of my timeshift-backups

That weird window is the vi or vim editor, which is the default editor for crontabs if no other editor has been specified for that user account by way of the $EDITOR variable.

  • vi or vim → Yes and already worked fine for crontab without root
  • $EDITOR-variable → Nice this did the trick

One exits vi by pressing Esc, followed by typing the following (if one does not want to save the file)… :arrow_down:

:q!

… followed by pressing Return/Enter

OK weird but thanks :rofl:

Use su instead of sudo. :arrow_down:

sudo su -
EDITOR=nano crontab -e

This was my prefered way to do it, due to the fact, that everything was already running (without root-permissions)
But sadly it seems that i get some errors in
journalctl
regarding
crond[725]: (root) CAN'T OPEN (/etc/crontab): Datei oder Verzeichnis nicht gefunden

So maybe i hopefully will find some time to check out your other solution “systemd timer” to get this working

Anyway thanks a lot for your very useful help!
I will give feedback (but i am very busy at the moment)

1 Like