I would like to automate some services using cron
jobs.
When I try to edit the crontab
file at /etc/crontab
, I am not able to save it as it says that it is read only.
What can I do?
I would like to automate some services using cron
jobs.
When I try to edit the crontab
file at /etc/crontab
, I am not able to save it as it says that it is read only.
What can I do?
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
.
crontab -e
will open your default editor, when you complete writing your crontab rules, you should save the file and exit the editor. You should NOT close the terminal at that point. you should first save the file...
– Yaron
Oct 18 '18 at 13:49