Editing crontab

Clearly over my head in this, but I started and despite reading, still confused.

I have a crontab that was created in terminal. It is set to run a script at a certain time. While fooling with it I created a number of crontabs as I was testing it out so that it would go off at different times.

Now, I would like to delete the crontabs that I don't want and leave the one that I do want.

When I enter crontab -e,it looks like there are previous cron action times that I set it to go off. Is this where I would delete the ones I don't want?...and how to edit it ?

Many thanks

g4 quicksilver, Mac OS X (10.4.11)

Posted on Feb 7, 2008 5:57 PM

Reply
Question marked as Top-ranking reply

Posted on Feb 8, 2008 5:57 AM

When you have run crontab -e, you are in the vi Editor, when you have not defined an another Editor. In this entry mode, you can delete, cut, copy and paste the entrys, but not writing.

In this Mode select the line, do you want to delete and press dd, or x for selection delete. This command removes the current line or sign under the cursor. Press u for undo, when you have made a mistake.

When you want to make changes, press i for insert. Have you done the work, press esc.

Then press keys for the sign :. When you see below the sign : type wq, this write the file and quit the Editor.

Vi is not an Friendly Editor, but very flexible.
22 replies
Question marked as Top-ranking reply

Feb 8, 2008 5:57 AM in response to mrokloricred37

When you have run crontab -e, you are in the vi Editor, when you have not defined an another Editor. In this entry mode, you can delete, cut, copy and paste the entrys, but not writing.

In this Mode select the line, do you want to delete and press dd, or x for selection delete. This command removes the current line or sign under the cursor. Press u for undo, when you have made a mistake.

When you want to make changes, press i for insert. Have you done the work, press esc.

Then press keys for the sign :. When you see below the sign : type wq, this write the file and quit the Editor.

Vi is not an Friendly Editor, but very flexible.

Feb 8, 2008 3:12 AM in response to mrokloricred37

Crontab -e used as standard the Editor vi. With the Environment Variable EDITOR, you can set an different Editor, such as nano, which is a little bit friendlier in the handling.

You set the Editor in the bash with: export EDITOR=nano. In the tcsh: setenv EDITOR nano. This Variable overwrites the standard setting.

At the next time, when you run crontab -e, you awake instead vi, nano.

Feb 7, 2008 8:42 PM in response to mrokloricred37

Just to be precise about terminology, you don't have a "crontab" or "crontabs". You have a "crontab file". And you have only one crontab file. But, your crontab file can have more than one entry in it.

Each entry in the file (each line in the file) represents one "job" that runs at the specified times.

So what you're asking is how to delete or remove some of the jobs from your crontab file.

As you surmised, you use crontab -e to edit, or change, the contents of the crontab file. To get rid of a job, delete the line in the file that represents it.

The crontab -e commmand opens the crontab file in a text editor, which you then use to edit the file. When done, save the file, and quit the editor.

I don't know what editor your system is using, so I can't help there. But you must have used it before, since you created the crontab file. Your task, then, is to find out what editor you're using, and what commands it uses to delete a line or lines.

Feb 7, 2008 11:01 PM in response to Don MacQueen1

I appreciate your patience.

The crontab manual says "Edit the current crontab using the editor specified by the VISUAL or EDITOR environment variables." Once again, I cannot follow this. Seems to me it is saying that I need to use an editor to do what I want, but don't know how to accomplish this. I had some excellent help getting the original crontab file entered.

How do I know which editor my system is using?
I assume, hopefully correctly, that I would need to enter some type of command in the crontab file that would then allow me to delete the jobs I want to delete.

Thanks again

Feb 8, 2008 5:12 AM in response to Zerwas

As I said, I was in too far over my head. I thought it would be simpler, but at this point I would need to be told exactly what to do to edit the jobs I have already created
For instance:

open terminal
at the prompt type in crontab -e
press the return key

I can open terminal but don't know any, I assume, Unix code. It isn't for a lack of trying as I have spent hours trying to figure this out.

Thanks for your understanding

Feb 8, 2008 6:31 AM in response to Zerwas

OK. Think I am getting there with your help. Just want to be absolutely sure of some of your instuctions please.

1- by typing crontab -e into terminal I am in the editor Right?

2- when you say select the line, you mean highlight the code for each job separately? or could all the jobs to be deleted be highlighted at once?

3- when I press dd or x do I press return after that?

4- you said... This command removes the current line or sign under the cursor. The cursor is different than the "prompt" I assume. The prompt being the small black box where you start typing when opening terminal for instance. Once the line is highlighted, it seems the cursor could be moved anywhere..

5-after completing press esc key right?

6- then press the colon and period :. one after the other right?

7-this will make the editor bring up the colon : sign after which I type wq?

I really don't want to create a bigger problem than I have so wanted to be absolutely sure. Once again I appreciate your help

Feb 8, 2008 6:52 AM in response to mrokloricred37

1: Yes
2: Yes, you only move the cursor to the line. For more lines you could also use the visual, with v or the expressions. But for the first time, it is easier to select each job seperatly.
3: No. The line removes immediately.

5: Only when you are in the insert Mode. Bur for sure, you can press it.
6: Press only for the colon.
7: Yes. You need below :wq. Then enter to save and quit.

Play a little bit. You can undo often with u, when you mean, you have make a mistake.
And for quit the editor without any changes Press colon and then you need q!

Feb 10, 2008 4:19 PM in response to mistersquid

True, however, since the original question was regarding a script set to run at a certain time, it looked like launchd was a better solution. Also, as the user stated that he was clearly over his head on this, then using a GUI such as Lingon to write the plist file is the best solution for this person. (All moot at this point, since he now knows how to use crontab -- not a bad thing, however, better if he knows crontab and launchd)

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Editing crontab

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.