Saving cron work in ubuntu

I am new to ubuntu and cron. I entered the following command on my command line:

crontab -e 

and I get the following output: "no crontab for teddy - using empty 888"

Then I enter when I want it to run (do I think this is correct? ... I want it to run once a day, every day at 8pm):

  00 18 * * * /*****/*****/****/test.php 

Here is my problem, I do not know how to exit the command line. Everything that I print gives me strange letters and input (return) does nothing. I read that this will do the job

  ESC : wq 

but it does not work for me. I tried to type this, I tried to press them at the same time, I tried to press one at a time. Nothing, still stuck. When I press ESC, it displays as ^ [.

This is probably a very simple question, and I apologize if this is stupid, but I’ve ever been stuck. Any help would be greatly appreciated.

thanks

PS I read somewhere that if this is your first job, you need to make the end line at the end of the cronjob ... is it just a press of the enter key or is it really input \ n?

+4
source share
3 answers

Teddy13, let me get some explanation here.

Ubuntu is the Linux distribution that you use. None of the commands you enter is exclusive to Ubuntu.

You ask questions on two separate questions. One of them: "How to write crontab". Another is "How to use vi, the default editor of the crontab command."

man crontab first to view the format of the entries in the file. Note that cron runs all executable files from the shell. You can run your "test.php" script if it is structured as a shell script, with the first line containing "shell magic" (for example, something like #!/usr/local/bin/php ).

Secondly, while vi is a powerful and well-loved text editor, it is not the easiest to use. I fully support any efforts you can make to learn how to use them, but until you feel comfortable, you might consider switching to "pico" or "ee" or "joe", which are much easier to learn, although they can do much less. You can install joe, for example, using the command: apt-get install joe run with administrator privileges. Then, to use joe to edit your crontab, add export VISUAL=/usr/bin/joe to the .bashrc in your home directory.

There is a lot of background information you might want to get. Read the lots. It's worth it.

UPDATE (per comment):

Here are the basic materials needed to edit your crontab.

  • crontab -e ... as you now know, this edits your crontab file with $ EDITOR or $ VISUAL, which is vi by default.
    • Inside vi, you are always in one of three modes. MOVEMENT mode allows you to move around the file using the arrows or H, J, K and L. You can delete lines with the help of "dd" or characters with "x". EDIT mode allows you to add or change text. In motion mode, use “i” or “a” or “o” to enter edit mode in different ways. Read the documents for more details. Thirdly, the COMMAND mode can be reached by pressing ":" in the driving mode. Here you can create various commands for saving, searching, bulk editing, etc.
    • In move mode, you can save the file and exit using "ZZ". From edit mode, you can do this with the "wq" command (hence, ": wq" is mentioned elsewhere).
  • Alternatively, you can install the new crontab piping information into the crontab command. Note that this will destroy any existing crontab that you may have. Run this in your shell, updating the URL of your script as needed:

    echo "0 20 * * * wget http://example.com/path/to/file.php" | crontab -

  • crontab -l will show you what the current crontab contains.

Hope this helps.

UPDATE # 2 (in the comments below):

 $ tmpfile=/tmp/foo.$$ $ crontab -l > $tmpfile $ echo "30 6 * * * Mail -s wakeup pager@example.net <<< 'Time to wake up.'" >> $tmpfile $ crontab - < $tmpfile && rm $tmpfile 
+8
source

You can try Ctrl + X. This will ask you to save the changes or not before exiting. In this, just give Shift + Y to get out of there. Give it a try.

+4
source

You need to press ZZ to exit (upper case "z" twice). Here's an article on setting up cron tabs - http://www.sophos.com/support/knowledgebase/article/12176.html

0
source

Source: https://habr.com/ru/post/1393909/


All Articles