Editing crontab [duplicate]
You should note that the reason you got an error specifying that the file is read-only is because you are trying to edit a root
owned file without being root
.
If you want to edit /etc/crontab
you should execute your editor as root - (e.g. sudo vi /etc/crontab
).
Note that it isn't the recommended way for regular users
The answer in here suggest using crontab -e
in order to edit the crontab
file.
Note that /usr/bin/crontab
is executed as root (set user-id root), and will allow you edit crontab for your own user - the file will be created in this root owned folder /var/spool/cron/crontabs
.
If you want to execute crontab services which will run as root You should use sudo
in order to became root.
You can either update /etc/crontab
directly by using sudo vi /etc/crontab
(or use any other text editor) and add a line for your job specifying the user as root...
Or you can run:
sudo crontab -e
Which will edit root
's crontab file in /var/spool/cron/crontabs
.