Forum Moderators: phranque
I want to set up a Cron Job and my hosting company said to use the standard Unix utility in the Shell.
Umm, how do I get to the Shell? What is it, a file? For some reason I always thought a Shell was like the DOS console in Windows.
I can figure it all out once I get access to it and see what it is.
Any help is appreciated.
Once you've got that, use the server and login/password details as supplied by your hosting company to conect to your site's server. Shell access will give you a standard Unix command prompt where you can issue the appropriate commands to set up your cron job.
I got PuTTY.
If I type this in the shell it works fine:
php mysite.com/www/cron/test.php
...but if I have this in my crontab nothing happens:
* * * * * php mysite.com/www/cron/test.php
Is that the way to execute it every minute? All it does is increment a value in a database for testing purposes.
I'm pretty sure the path in the crontab is wrong but I don't know what to set it to. Also, in the .php file I had an include that didn't work (not found.)
How do I get the paths right? Today is the first time I used a Unix shell.
Thanks.
This is a PERL script. Chmod it to 755, run it from the web (or it's equivalent in PHP):
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print '<HTML><HEAD><TITLE>Environment Variables</TITLE></HEAD><BODY>', "\n\n";
foreach $varname (sort keys %ENV) {
print '<TR><TD>', $varname, '</TD><td>', $ENV{$varname}, '</TD></TR>', "\n";
}
print '</TR>', "\n", '</TABLE></BODY></HTML>', "\n\n";
The document root environment variable will be how you get to your file locally. It will probably be something like /usr/var/www/yoursite.com/yourdirectory
DELETE THIS SCRIPT, or any other environment variable scripts, from your server IMMEDIATELY after getting the info you need.
Google for cron to get your cron timing correct, and you will possibly have to execute restart cron from the shell for it to begin working.
I figured it all out and got my cron job working.
I used 'pwd' to get the path to the .php file I want executed at intervals and 'whereis' to get the php path, both of which were needed in the crontab.
Today I learned how to use the Shell, some Unix directory commands, that vi text editor (I thought maybe the Windows \r\n was messing something up so I used vi), and setting up a cron table, not bad for a day's work :)
Thanks again.