|
Creating a Cron Job in 1and1 shared web hosting
A quick intro to the task is that cron jobs are acheivable through OneandOne shared web hosting packages of 'Business Pro' and 'Professional'. It took me about a day-and-a-half of heartache getting there but eventually we managed to get the server to deliver the scheduled task.
What we wanted to do was automate a dataabse search and to post the results through email, using php as the processing script language.
How to do it
I will assume that you already know how to create a database through OneandOne, and already know how to use php to access that database to do your search. What you really need to know is how to set up the cron job itself. I'll start with the solution and work backwards from here.
The Solution in a Nutshell
The solution is to use the SSH command line through a facility like 'Putty' to get to your root directory. The 1and1 help files are very good at providing you your access codes (basically you need your domain name: www.yourdomain.co.uk, username: u3527**** and password: p*****rd). See the image below for what your Putty command line screen looks like. The image below is a listing (crontab -l) of two scheduled tasks which take place on the server at 1:58am and 1:12am every day. There are two lines here simlpy becasue I found two different ways of doing the saem task and wanted to share them with you, however any individual approach will work.

The magic key to setting up these cron jobs turns out to be providing the correct path to 'wget' or 'lynx', with oneandone it happens to be the /kunden/usr/bin/wget path and /kunden/usr/bin/lynx path that you never get to find out about. The rest is simply pointing to the file that you want to be executed, in this case a php file that opens a database connection, runs a sql script on a table and returns the result as an email back to me.
What you will find however is...you may need to wait a while
The biggest problem I had however is that I arrived at the above solution(s) after only a few hours of messing around with Google and crontab, but the solution didn't seem to work. I decided to leave my crontab code on the server while I slept on it and hey presto the next day it was working. I really don't know why it took all-night to work but it hasn't stopped working since and my server carries out this (and many other) task without hesitation. My advice is have the courage of your convictions and let the 1and1 shared hosting server catch up with your crontab command.
crontab -e & crontab -l
To enter or edit a crontab you need to enter crontab -e <return>, from here you need to press 'i' to insert or edit the current set of crontab commands.
To save the crontab you have just entered or edited don't forget to press Esc-Shift-Z-Z rather like you would press Ctrl-Alt-Delete on a PC. Otherwise your cron job will not save.
To simply list the current set of cronjobs you simply type crontab -l <enter> at the command line.
Setting the Cronjob timing
The easiest bit is setting the cron job timings, there are pages and pages of this on line so I won't bore you, just google it. The hardest bit is getting the cronjob to work in the first place.
Good luck and if you are having difficulty contact me.
Once logged in to your root directory in Putty all you have to do is enter you cron job via the edit screen.
|