I am new to ubuntu and cron job. I have entered the following into my command line:
crontab -e
and I get the following output: "no crontab for teddy - using an empty one 888"
Then I enter when I want it to execute (I believe this is right?... I want it to run once a day, everyday at 8pm):
00 18 * * * /*****/*****/****/test.php
Here is my problem, I dont know how to exit back to the command line. Everything I type gives me weird looking letters and enter (return) doesn't do anything. I have read that this will do the job
ESC : w q
but its not working for me. I tried typing that in, I tried pressing them at the same time, I tried pressing one at a time. Nothing, still stuck. When I press ESC, it comes out as ^[.
This is probably very easy question and I apologize if it is stupid but I have been stuck for sometime. Any help would much appreciated.
Thank you
P.S. I read somewhere that if this is your first job that you need to to do an end line at the end of the cronjob... is this a simple enter key press or actually typing \n?
Teddy13, let's get some clarifications here.
Ubuntu is the distribution of Linux you are using. None of the commands you're typing are exclusive to Ubuntu.
You're asking questions about two separate issues. One is "How do I write a crontab". The other is "How do I use vi, the default editor of the crontab command".
First, man crontab
to review the format for entries in the file. Note that cron runs things that are executable from the shell. You can only run your "test.php" script if it is structured like a shell script, with the first line containing "shell magic" (i.e. something like #!/usr/local/bin/php
).
Second, while vi is a powerful and well-loved text editor, it's not the easiest to use. I fully support any efforts you may make to learn how to use it, but until you're comfortable with it, you might want to consider switching to "pico" or "ee" or "joe", which are all much easier to learn, though they can do much less. You can install joe, for example, with the command: apt-get install joe
run as root. Then to use joe to edit your crontab, add export VISUAL=/usr/bin/joe
to the .bashrc
file in your home directory.
There's a lot of background information you may want to get. Read lots. It's worth it.
UPDATE (per comment):
Here's the basic stuff you need to edit your crontab.
crontab -e
... as you now know, this edits your crontab file using $EDITOR or $VISUAL, which defaults to vi
.
Alternately, you can set a new crontab by piping information into the crontab command. Note that this will erase any existing crontab you may have. Run this in your shell updating the URL of your script as required:
echo "0 20 * * * wget http://example.com/path/to/file.php" | crontab -
crontab -l
will show you what your current crontab contains.
Hope this helps.
UPDATE #2 (per comments below):
$ tmpfile=/tmp/foo.$$
$ crontab -l > $tmpfile
$ echo "30 6 * * * Mail -s wakeup [email protected] <<< 'Time to wake up.'" >> $tmpfile
$ crontab - < $tmpfile && rm $tmpfile
You can try Ctrl+X. This will ask you for changes to save or not before exit. In that just give Shift+Y so you will get out of there. Try it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With