Following on from running my first cron job with 1and1 hosting what I really wanted to do was to be able to run a php script, perl script or some other form of script on a timed basis. This article is a description of setting up a cron job on 1and1 hosting to run a simple "hello world" style example. I have the 1&1 linux business hosting package so can only confirm this example works with that.
First I set up my helloworld.php script, this was a simple script to create a file called helloworld.txt and write the words "hello world" to that file and save it.
<?php
// the filename
$filename = 'helloworld.txt';// the content
$content = 'hello world';// create the file
$f=fopen($filename, "wb");
fputs($f, $content);
fclose($f);// now done
?>
I tested this file by running it on my server and it worked fine. I would recommend you do the same.
The next thing I had to do was log on to my 1and1 server using SSH, the program I use for this is PuTTY which I have been using since university and works well. You enter the username and password for FTP and SSH access to your site in the PuTTY command prompt and then are logged into the site. The next two steps you have to go through are:
- to find the location of your current directory: enter "pwd" to find this... mine was: "/kunden/homepages/XX/dXXXXXXXX/htdocs"
- to find the location of php on your machine to do this I entered the command "php -info" in the command prompt and looked for the location in the output which was: "/usr/local/bin/php" however due to the nature of 1and1 hosting the full path was actually "/kunden/usr/local/bin/php"
Now I had to create my crontab file. In the file below the 14 refers to the 14minutes past the hour, you can find out about the 4 *'s from the crontab page on wikipedia. So I entered the command "crontab -e" (which means edit crontab) and came to the VI editor which 1and1 use on their debian linux installation. In that line I entered the command: "14 * * * * /kunden/usr/local/bin/php /kunden/homepages/XX/dXXXXXXXX/htdocs/helloworld.php > /dev/null" all on one line. This command means at 14minutes past every hour on every day using the program found at /kunden/usr/local/bin/php execute the file found at /kunden/homepages/XX/dXXXXXXXX/htdocs/helloworld.php and send the output to the location /dev/null (which means get rid of the output). Using this command I found that on 1and1 hosting my helloworld.txt file was updated between 14 and 18minutes past every hour.
I know this description would have helped me had it been available when I was looking for information on running a php file through a cron job on 1and1. I hope it helps you.
Very useful for me…I’m looking for some idea to redesign our logo.Thanks
Posted by: yiwu china | December 28, 2010 at 04:00 AM
He has made his weapons his gods.
When his weapons win he is defeated himself. O(∩_∩)O~
Posted by: Air Jordan 13 | December 20, 2010 at 12:45 AM
I did not discuss that particular issue!!
Posted by: moncler jackets | November 15, 2010 at 04:53 PM
This program looks so interesting and really helpful for companies that have big business and besides if it is added to Linux it will work better than if you work with windows.
Posted by: Generic Viagra | November 12, 2010 at 01:23 PM
Hey thanks for sharing this information, a few days back I was looking for it but I couldn't found it. In fact this information was pretty useful for a homework that I really need to do it.
Posted by: Kamagra Gel | November 12, 2010 at 12:37 PM
oh so funny!
Posted by: moncler jackets | November 11, 2010 at 10:42 PM
yes you are right!
Posted by: Air Jordans | November 11, 2010 at 07:15 PM
I appreciate your comments very much and want to thank you. Your blog is so great, and can i buy some ad from you blog? If so, just email me and tell me the ad type and charge? Thanks so much
Posted by: air jordans | October 29, 2010 at 08:27 PM
Note that the default /kunden/usr/local/bin/php may not work if your script requires php 5. Instead use:
/kunden/usr/local/bin/php5
You can try your script out by typing it into the shell first e.g.
/kunden/usr/local/bin/php5 /kunden/homepages/xx/dxxxxxxxxx/htdocs/xxx.php
Posted by: anon | August 09, 2010 at 04:53 AM
You admission the username and countersign for FTP and SSH admission to your armpit in the PuTTY command alert and again are logged into the site.
Posted by: Vimax | May 04, 2010 at 08:45 AM