Useful UNIX Tasks
Here are some of the most useful things you can do from
telnet.
Determine the full path name of your script or file
Sometimes when you are configuring scripts, it will ask
you to enter the full UNIX path name for a file or directory.
Here's an example from the popular guestbook.cgi script:
$guestbookurl = "http://your.host.com/~yourname/guestbook.html";
$guestbookreal = "/home/yourname/public_html/guestbook.html";
The second variable above is asking for the "real" path to the
guestbook file. The easiest way to do this is to log on via
telnet, change directories to whereever the guestbook file is
located and type the following command:
pwd
This will give you the information to put in place of /home/yourname/publich_html
in the example above.
Finding "sendmail"
If you are installing a script on a UNIX server that needs
to send email, you will undoubtedly be asked to fill in a
variable with the location of the UNIX sendmail program. Again
from the guestbook.cgi script, it looks like this:
# If you answered 1 to $mail or $remote_mail you will need to fill out
# these variables below:
$mailprog = '/usr/lib/sendmail';
$recipient = 'you@your.com';
Often your ISP will have a list of frequently asked questions
on their website, and the location of sendmail should be on
that list. But here's how to fnd it from telnet:
Likely spots for sendmail are:
/usr/lib/sendmail
/usr/sbin/sendmail
From a telnet session, you can type the following commands:
ls /usr/lib/sendmail
or
ls /usr/sbin/sendmail
to see which one is correct. If it's not correct, it'll say
something like "file not found". If neither of these is correct,
you can try these commands to search for the program:
which sendmail
or
find / -name sendmail -print
Finding the path to the perl executable
Again, this is a common setup question when installing CGI
scripts. The first line of every Perl script should look like
this:
#!/bin/perl
where /bin/perl is changed depending on where the perl program
is found on your server. This is also a common entry on your
ISP's FAQ page, but if you want to determine it for yourself,
use this telnet command
which perl
Debugging scripts
One of the most useful things to do in terms of debugging
CGI scripts is to "run" the script from the UNIX command line.
The advantage to doing this (as opposed to just trying to
run the script from your webpage, is that UNIX will give you
more information about any errors in the script itself.
If you are using a Perl script, this is very easy to do.
First you must get yourself into the directory where the script
resides, then you type a perl command to run the script. Typically,
this command is:
perl <scriptname>
or sometimes (if the first doesn't work and you see a message
about "too late for the -T flag")
perl -T <scriptname>
After you type this comand, you will either see error messages
on the screen, or you may see a bunch of HTML fly by. Seeing
HTML generally means that the script is running properly and
there are not Perl syntax errors. If there are error messages,
they usually contain a line number and you can start investigating
the script error from that point.
Legend:
Perl code
UNIX command
Related tutorials
UNIX directory structure
UNIX file permissions
Basic UNIX commands
Using telnet
|