Forum Moderators: phranque

Message Too Old, No Replies

Access my Shell?

...how?

         

Emperor

12:10 am on Jul 7, 2005 (gmt 0)

10+ Year Member



Hi guys,

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.

encyclo

1:05 am on Jul 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Assuming your home machine is running Windows, first step is to download "Putty", which is a free (and excellent) tool for SSH (Secure SHell) connections:

[chiark.greenend.org.uk...]

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.

2by4

3:16 am on Jul 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The shell is just like the dos console in windows, except the dos console is just a fake shell, and is much less powerful than the unix shell, in unix you're looking at a real shell.

Emperor

10:42 pm on Jul 8, 2005 (gmt 0)

10+ Year Member



Hi guys,

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.

rocknbil

10:56 pm on Jul 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It only works because of your current location in the system when you type it in. You want the full virtual (or real) local path from the root of the system.

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.

encyclo

11:28 pm on Jul 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Surely to get the working directory you only need to type the command
pwd
(Print Working Directory)? Then you can use that path to run your script.

Emperor

5:17 am on Jul 9, 2005 (gmt 0)

10+ Year Member



Hi guys,

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.

2by4

6:09 am on Jul 9, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



No, not bad at all, nice going.