ferdi
Posts: 45
Joined: Mon Jul 30, 2012 4:10 pm

edit crontab

Mon May 13, 2013 5:58 am

I can not edit my crontab file
Attachments
cron.JPG
cron.JPG (33.51 KiB) Viewed 29843 times

User avatar
AndyD
Posts: 2333
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
Contact: Website

Re: edit crontab

Mon May 13, 2013 6:16 am

Hi,

You just need "crontab -e" not "edit crontab -e". The -e option for crontab starts the default editor and edits the crontab entry.

ferdi
Posts: 45
Joined: Mon Jul 30, 2012 4:10 pm

Re: edit crontab

Mon May 13, 2013 12:25 pm

My file is /etc/crontab,
crontab - e open instead /tmp/crontab.NJf3oc/crontab
How to solve, thanks
Attachments
cron1.JPG
cron1.JPG (26.4 KiB) Viewed 29815 times

User avatar
rpdom
Posts: 15901
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: edit crontab

Mon May 13, 2013 12:57 pm

You do not normally put entries in the /etc/crontab file, although it is possible and will work. If you really need to do that, you can use "sudo nano /etc/crontab".

The usual method is to edit the crontab for the user. What crontab -e does is to make a temporary copy of the user's current crontab file, then start an editor (like nano) on that file. When you edit and save that file, it will do a quick syntax check and then update the user crontab file.

ferdi
Posts: 45
Joined: Mon Jul 30, 2012 4:10 pm

Re: edit crontab

Tue May 14, 2013 2:45 pm

I used sudo nano /etc/crontab, but the system creates a sample file and doesn't edit the existing file
Attachments
cron3.JPG
cron3.JPG (31.1 KiB) Viewed 29778 times

Maxion
Posts: 138
Joined: Mon Dec 03, 2012 2:22 pm

Re: edit crontab

Tue May 14, 2013 2:47 pm

ferdi wrote:I used sudo nano /etc/crontab, but the system creates a sample file and doesn't edit the existing file
I'd appreciate it if you took 10 more seconds to read the replies people give you.

"crontab -e" creates a temporary copy of the cron configuration file and opens it up in a text editor. Once you save and close the file your changes are appended to cron.

DirkS
Posts: 10086
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: edit crontab

Tue May 14, 2013 2:49 pm

I used sudo nano /etc/crontab, but the system creates a sample file and doesn't edit the existing file
As rpdom said you don't start the editor yourself. Using 'crontab -e' the system will make a copy, start the editor using that copy and replace the original after you finished editing.

Gr.
Dirk.

ferdi
Posts: 45
Joined: Mon Jul 30, 2012 4:10 pm

Re: edit crontab

Tue May 14, 2013 2:57 pm

thanks for the answers,
but my question is "how can I edit the original file ?"

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: edit crontab

Tue May 14, 2013 2:59 pm

Well, as always, there is a distinction between discussing what he did do (and the results, good or bad, that he got therefrom) vs. a discussion of what he should have done to achieve what are (or should be) his actual goals.

Now, we all know that what he should be doing is to forget about /etc/crontab entirely, and use "crontab -e" to edit a user-specific crontab file - and that that would solve all issues.

But, OTOH, the fact is that doing "[sudo] [editor] /etc/crontab" should (and does) work. And even if it isn't the approved method, the fact is that it does work - and, as the comments in the file tell you, you don't need to do anything special (see below) to make it work. All you do is edit the file and (Voila!) it works.

Note on "anything special": Note that, traditionally, the cron daemon, for efficiency reasons, needs to be "woken up" when you make changes to your crontab file. So, simply editing the file (if you could, because of permissions issues) won't do anything useful. That's why the crontab command exists; it edits your file and then "installs" it - i.e., sends a signal to the daemon to cause it (the daemon) to re-scan the file(s) in the "cron" spool directory.
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

DirkS
Posts: 10086
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: edit crontab

Tue May 14, 2013 3:07 pm

ferdi wrote:thanks for the answers,
but my question is "how can I edit the original file ?"
As said several times already: by using either 'crontab -e' (for current user) or 'sudo crontab -e' (for root).
You see a temporary file in the editor, but the original file is being replaced after you close the editor.
So you *are* editing the original (in a roundabout way).

I get the feeling I'm repeating myself here... :roll:

Gr.
Dirk.

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: edit crontab

Tue May 14, 2013 3:16 pm

DirkS wrote:
ferdi wrote:thanks for the answers,
but my question is "how can I edit the original file ?"
As said several times already: by using either 'crontab -e' (for current user) or 'sudo crontab -e' (for root).
You see a temporary file in the editor, but the original file is being replaced after you close the editor.
So you *are* editing the original (in a roundabout way).

I get the feeling I'm repeating myself here... :roll:

Gr.
Dirk.
That, of course, depends entirely on what the OP actually means by "the original file".

See my previous response.
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

User avatar
jojopi
Posts: 3110
Joined: Tue Oct 11, 2011 8:38 pm

Re: edit crontab

Tue May 14, 2013 3:58 pm

ferdi wrote:I used sudo nano /etc/crontab, but the system creates a sample file and doesn't edit the existing file
Your image shows that you were editing /etc/crontab directly, but the comments in the file appear to belong to a per-user crontab. I cannot explain that. Are the four standard jobs missing from the bottom of the file as well?

The main reason that "crontab -e" edits a temporary copy is that users do not have permission to change their crontabs in place. There is no way to set the permissions so that a user can create his crontab if it does not exist, but can not create another user's crontab, so a set-user-id wrapper is provided.

Arguably, therefore, root should not bother with "crontab -e" and should edit /etc/crontab or /etc/cron.d/* directly. Note that the system crontabs have an extra field, username, compared to the per-user crontabs!

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: edit crontab

Tue May 14, 2013 4:18 pm

Arguably, therefore, root should not bother with "crontab -e" and should edit ... /etc/cron.d/* directly.
Not really. See my previous previous post.
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

User avatar
rpdom
Posts: 15901
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: edit crontab

Tue May 14, 2013 4:57 pm

ferdi wrote:I used sudo nano /etc/crontab, but the system creates a sample file and doesn't edit the existing file
The image you posted (cron3.JPG) when you said this clearly showed you editing editing /etc/crontab. Therefore I can't understand why you say it isn't??

The image you posted previously (cron1.JPG) showed the results of crontab -e and was editing a copy of the user crontab called /tmp/crontab.NJf3oc/crontab, which is what it is supposed to do. When you save and exit, that will be saved as your current user's crontab in /var/spool/cron/crontabs/<username>

User avatar
jojopi
Posts: 3110
Joined: Tue Oct 11, 2011 8:38 pm

Re: edit crontab

Tue May 14, 2013 5:39 pm

rpdom wrote:The image you posted (cron3.JPG) when you said this clearly showed you editing editing /etc/crontab. Therefore I can't understand why you say it isn't??
However, the comments at the start of the file do not match those expected in /etc/crontab. They match the comments normally added when creating a new per-user crontab.

Since both sets of comments normally go on to describe the field order, and the fields differ between system and per-user crontabs, I find this suspicious.

We cannot see enough of /etc/crontab to be sure, but it appears to have been clobbered.

User avatar
rpdom
Posts: 15901
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: edit crontab

Tue May 14, 2013 5:43 pm

jojopi wrote:Since both sets of comments normally go on to describe the field order, and the fields differ between system and per-user crontabs, I find this suspicious.

We cannot see enough of /etc/crontab to be sure, but it appears to have been clobbered.
I agree.

I think the OP should either reimage their system from scratch, or extract the correct /etc/crontab from a clean image and use that. Then work out what they really want to do and which crontab to use for it.

I'm now wondering if by "original file", they mean that they have lost the original /etc/crontab somehow and want to recover it?

ferdi
Posts: 45
Joined: Mon Jul 30, 2012 4:10 pm

Re: edit crontab

Tue May 14, 2013 8:41 pm

I apologize for my poor knowledge,
I have verified this: If I use sudo nano / etc / crontab, the system really opens the file / etc crontab, but this file is not what the system uses to perform certain operations,
if I type crontab-e, the system opens the file / tmp/crontab.Z38sRe/crontab, which is effectively the one set and utilized by the system,
In fact, after editing and saving the file, the system replies: crontab: installing new crontab
so the question is: "where is this file?"

User avatar
jojopi
Posts: 3110
Joined: Tue Oct 11, 2011 8:38 pm

Re: edit crontab

Tue May 14, 2013 9:13 pm

The system uses all crontabs: /etc/crontab, plus every file in the directory /etc/cron.d/, plus every per-user crontab. Conventionally, /etc/crontab also indirectly executes all the files in directories /etc/cron.{hourly,daily,weekly,monthly}/ at the relevant times.

The per-user crontabs are stored in directory /var/spool/cron/crontabs/. But you should not need to know that. You can view a user crontab with "crontab -l" or "sudo crontab -l -u $USER".

ferdi
Posts: 45
Joined: Mon Jul 30, 2012 4:10 pm

Re: edit crontab

Wed May 15, 2013 5:44 am

jojopi wrote:... You can view a user crontab with "crontab -l" or "sudo crontab -l -u $USER".
thanks, very clear

Houtkamp
Posts: 8
Joined: Wed Dec 18, 2013 6:50 pm

Re: edit crontab

Wed Dec 18, 2013 6:52 pm

Hate to say it, but it looks like we still need at least one COMPLETE response to this very important problem: exactly how do you make an application run on startup?

User avatar
rpdom
Posts: 15901
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: edit crontab

Thu Dec 19, 2013 4:56 am

Houtkamp wrote:Hate to say it, but it looks like we still need at least one COMPLETE response to this very important problem: exactly how do you make an application run on startup?
There are a few ways to do that. An init script in /etc/init.d, an entry in /etc/rc.local, a crontab entry with the time/date fields set to "@reboot" - or do you mean when your desktop starts?

All of these options have been described many times on the forums and can be found with a quick web search.

[edit]
for example https://www.google.com/search?q=site%3A ... at+startup

DavidMS
Posts: 139
Joined: Fri May 25, 2012 8:48 pm
Contact: Website

Re: edit crontab

Sat Dec 21, 2013 8:24 am

Not sure if this adds anything, but I was having a problem this morning getting crontab to update using the sudo crontab -e.
After reading this I noticed that if you exit nano by performing cntr o the cntr z crontab is not updated. Thinking about it this does not surprise me but I had not noticed my default way to exit nano was to save then terminate with cntr z, fine for updating Python code but not for crontab
http://meanderingpi.wordpress.com/
11 Raspberry Pi's and counting....

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: edit crontab

Sat Dec 21, 2013 8:33 pm

terminate with cntr z
That's your problem, right there. The phrase quoted above makes no sense and should not be in anyone's lexicon.
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

User avatar
rpdom
Posts: 15901
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: edit crontab

Sat Dec 21, 2013 9:14 pm

Agree with Joe (well, there's a first time for everything ;) ).

Ctrl-Z won't terminate nano. It will just leave it stalled in the background.

You need to exit it properly (Ctrl-X) for cron to finish updating the proper crontab file.

If you typed "fg" after doing the Ctrl-Z, you would find yourself back in the same nano session - still editing that file.

jan_paulussen
Posts: 7
Joined: Mon Aug 28, 2017 7:22 am

Re: edit crontab

Wed Dec 06, 2017 3:31 pm

I was trying to get a crontab going, and had some problems as well.
Even if one does the crontab -e and saves by CTRL-O, and then leaves properly with the CTRL-X, it still does not update the crontab.
One has to specific leave with the CTRL-x without saving first, and then say 'yes' to the prompt to have the real crontab actually updated.
If one rightfully saves first, and only exits thereafter without again having the question on saving because you just saved before, it does not work... Funny, but that's the way it seemed to be.
I think that might have been the problem of the initial post, as it was a problem to me at first too...
I hope this helps to solve, as it did to me...

Return to “Beginners”