Previous 1 2 Next 22 Replies Latest reply: Feb 10, 2008 5:56 PM by mistersquid
APPLEAL Level 2 Level 2 (155 points)
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)
  • Don MacQueen1 Level 4 Level 4 (2,470 points)
    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.
  • APPLEAL Level 2 Level 2 (155 points)
    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
  • Zerwas Level 4 Level 4 (1,140 points)
    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.
  • APPLEAL Level 2 Level 2 (155 points)
    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
  • Zerwas Level 4 Level 4 (1,140 points)
    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.
  • APPLEAL Level 2 Level 2 (155 points)
    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
  • APPLEAL Level 2 Level 2 (155 points)
    Have been "experimenting"
    Seems you have to hit the x key repeatedly to delete one character at a time. What if the prompt is on a line you want to keep? How to move the prompt to a different area?
  • Zerwas Level 4 Level 4 (1,140 points)
    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!
  • Zerwas Level 4 Level 4 (1,140 points)
    Use the cursors to navigate to the lines.
  • APPLEAL Level 2 Level 2 (155 points)
    I can almost taste victory

    I have deleted everything I wanted to.
    I am not doing any inserting.

    The cursor is now sitting on the last letter of the following cron task

    40 00 * * * osascript /Documents/crontab/myASCode.scpt

    The next thing to do is type :wq at the point where the cursor is ???
    Then quit terminal?
  • APPLEAL Level 2 Level 2 (155 points)
    Assume I need to press return key after entering :wq right?
  • Zerwas Level 4 Level 4 (1,140 points)
    YES. When below stands :wq then hit enter.
  • APPLEAL Level 2 Level 2 (155 points)
    I got brave and did the :wq looks good. In order to test this I wanted to change the time on the cronjob.

    Would I delete the character/s in the time the same way I deleted the code?
    Then I would need to type i to insert?
    type in new time?
    press escape?
    then :wq
    then return?
  • Zerwas Level 4 Level 4 (1,140 points)
    Yep. You can also use the shorter combination s, instead first x and then i. s removed the character under the cursor and switched to the insert mode.
Previous 1 2 Next