The Best Shopping On The Planet |
About Us Search EarthlingsUnited Customer Service |
EarthlingsUnited welcomes you to web site development tutorial. This is the most comprehensive e-commerce site development tutorial you will find anywhere at any price. This one is free. |
Home
Day 1: Web Development Tools |
Class Goals
|
PERL is an interpreted language optimized for scanning arbitrary text files, extracting information from those text files, and printing reports based on that information. It's also a good language for many system management tasks. The language is intended to be practical (easy to use, efficient, complete) rather than beautiful (tiny, elegant, minimal). It combines (in the author's opinion, anyway) some of the best features of C, sed, awk, and sh, so people familiar with those languages should have little difficulty with it. (Language historians will also note some vestiges of csh, Pascal, and even BASIC-PLUS.) Expression syntax corresponds quite closely to C expression syntax. Unlike most Unix utilities, perl does not arbitrarily limit the size of your data -- if you've got the memory, perl can slurp in your whole file as a single string. Recursion is of unlimited depth. And the hash tables used by associative arrays grow as necessary to prevent degraded performance. Perl uses sophisticated pattern matching techniques to scan large amounts of data very quickly. Although optimized for scanning text, perl can also deal with binary data, and can make dbm files look like associative arrays (where dbm is available). Setuid perl scripts are safer than C programs through a data flow tracing mechanism, which prevents many stupid security holes. If you have a problem that would ordinarily use sed or awk or sh, but it exceeds their capabilities or must run a little faster, and you don't want to write the silly thing in C, then perl may be for you. There are also translators to turn your sed and awk scripts into perl scripts. OK, enough hype.
A great PC binary is available for the PC that includes the Apache server, PERL, and many PERL modules.
CPAN Comprehensive Perl Archive Network
IndigoPerl PC Binary for Apache
and PERL
PerlMongers The Perl advocacy people
Great Tutorials on PERL
Simple Perl
Tutorial - Use this to get started in PERL. Print this out and staple
it together.
Perl
Manual - Use this after you have a few scripts under your belt. Print
this out and staple it together.
PERL Script Archives
Eventually you may find that you would like your web pages to perform functions other than display your content. These functions include forms processing, internal search engine, tracking visitors. That requires CGI based software. Most of the web is based on PERL scripts. The following links are excellent sources of PERL scripts and how to get started in this area.
MattsScriptArchive Nice place to start to learn and install some useful and simple CGI's.
BigNoseBird.com The is step 2 in learning CGI programing. It is an excellent site with slightly more complex scripts.
CGI Resources.com This is one of the largest repositories of CGI resources on the WEB. Go here after you have installed / modified 2 or 3 scripts and made them work.
Perl Manual This is a single page version of the popular perl manual maintained many places...
PERL Code Examples
Hello World
#!/usr/local/bin/perl print "Content-type: text/html\n\n"; print "hello";
Tail Report
#!/usr/local/bin/perl print "Content-type: text/html\n\n"; print "<HTML><HEAD><TITLE>Tail Report</TITLE></HEAD>"; print "<BODY BGCOLOR=\"#ffffff\" TEXT=\"#000000\">\n"; print "<P><CENTER><H3>Tail Analyze</H3><P></CENTER>\n"; @stuff = `tail -50 ../cgi-bin/log_1.dat`; foreach $stuff (@stuff) {print "<NOBR>$stuff</NOBR><BR>\n";} print "</BODY></HTML>\n";
Log File
#!/usr/local/bin/perl # directory path $logfile = "/home/wsobkiw/cgi-bin/log_1.dat"; # domain address - req's $domain = "mydomainname"; ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); if ($sec < 10) {$sec = "0$sec";} if ($min < 10) {$min = "0$min";} if ($hour < 10) {$hour = "0$hour";} if ($mon < 10) {$mon = "0$mon";} if ($mday < 10) {$mday = "0$mday";} $year = 2000 + $year - 100; $month = ($mon + 1); $date1 = "$month/$mday/$year, $hour\:$min\:$sec"; if (! open(LOG,">>$logfile")) {print "Content-type: text/html\n\n"; print "Couldn't open $logfile\n"; exit;} print LOG "\n$ENV{'REMOTE_HOST'}, -$ENV{'REMOTE_IDENT'}, $date1, 1, 2, $domain, 3, 4, 5, 6, 0, GET, $ENV{'DOCUMENT_URI'}, $ENV{'HTTP_USER_AGENT'}, $ENV{'HTTP_REFERER'}, c, b,"; close (LOG);
Random Images
#! /usr/local/bin/perl srand(time ^ $$); $num = rand(@images); # Pick a Random Number $num = 0; $|=1; $mypic[0]="/home/wsobkiw/public_html/0.jpg"; $mypic[1]="/home/wsobkiw/public_html/1.jpg"; $mypic[2]="/home/wsobkiw/public_html/2.jpg"; $mypic[3]="/home/wsobkiw/public_html/3.jpg"; $mypic[3]="/home/wsobkiw/public_html/4.jpg"; srand(time ^ $$); $pick = rand(@mypic); print "Content-type: image/jpeg\n\n"; open (BANNER,$mypic[$pick]); print <BANNER> ; close (BANNER);
All PERL scripts, once uploaded to the server, need to have their permissions changed so that they can execute. Some ISP's provide a framework that allow simple UNIX commands to be executed just for this purpose. The normal mode of operation is telnet. The following is a list of UNIX commands that you will need to manage your site.
man |
this is the help function in UNIX land, for example man ls | |
ls -al |
list the contents of the current directory and show the permissions | |
cd |
change directory, for example cd .., cd public_html, cd /home/usr | |
chmod |
change the premissions of one or more files | |
mkdir |
make directory | |
rm |
remove file | |
rmdir |
remove directory | |
find |
find a file for example find . -name "somefile" -print | |
passwd |
change your password | |
which |
finds the path of programs you need, for example which sendmail |
All scripts should be set to 755 and all data files that scripts use should be set to 666. If your domain runs as its own web server then data file permisisons that scripts use do not need to be modified. So:
chmod 755 *.cgi
chmod 755 *.pl
chmod 666 *.dat
chmod 666 *.log
chmod 666 *.txt
The privileges are shown when your perform an ls -al where the settings are as follows:
rwx | rwx | rwx |
user | group | system |
111 | 111 | 111 |
The following is a list of UNIX commands that I have found helpful when modifying web sites on the server. Most UNIX commands have many options and parameters which I have not listed here. Instead I have given examples of practical uses. For more complete information on most command, you can refer to the online manual by typing man [command] at the UNIX prompt. Some commands you can type [command] --help or [command] -?
Note, when I specify something in brackets like so: [filename] that is to indicate that you type in a filename or whatever. Do not include the brackets in your command.
Navigating UNIX: / (refers to the root directory on the server) ./ (the current directory that you are in) ../ (parent directory of your current directory) pwd (shows what you current directory is - giving the full path) ls (lists all the files in your current directory) ls -al (lists filenames + information) ls -alR (lists filenames + information in all subdirectories) ls -alR | more (lists filenames + information in all subdirectories, pausing when the screen become full) ls -alR > result.txt (lists filenames + information in all subdirectories, and ouputs the results to a file instead of the screen) ls *.html (lists all files ending with .html) ls -al /home/usr/bob/ (lists files + info for /home/usr/bob) cd (changes you to a new directory) cd images cd / (changes you to the root directory) cd /home/usr/images cd .. (this goes back one directory) Moving, Copying and Deleting Files: mv [old name] [new name] (move/rename a file) cp [filename] [new filename] (copy a file) rm [filename] (delete a file) rm * (delete all files in your current directory) rm *.html (delete all files ending in .html in your current directory) Creating, Moving, Copying and Deleting Directories: mkdir [directoryname] (creates a new directory) ls -d */ (lists all directories within current directory) cp -r [directoryname] [new directoryname] (copy a directory and all files/directories in it) rmdir [directoryname] (remove a directory if it is empty) rm -r [directoryname] (remove a directory and all files in it) Searching Files and Directories find / -name [filename] -print (search the whole server for a file) find . -name [filename] -print (search for a file starting with the current directory) find / -name [directoryname] - type d -print (search the whole server for a direcory) grep [text] [filename] (search for text within a file) sed s/[oldtext]/[newtext]/g [filename] (searches file and replaces all occurances of [oldtext] with [newtext] File and Directory Permissions There are three levels of file permission: read, write and execute. In addition, there are three groups to which you can assign permission, The file owner, the user group, and everyone. The command chmod followed by three numbers is used to change permissons. The first number is the permission for the owner, the second for the group and the third for everyone. Here are how the levels of permission translate: 0 = --- (no permission) 1 = --x (execute only) 2 = -w- (write only) 3 = -wx (write and execute) 4 = r-- (read only) 5 = r-x (read and execute) 6 = rw- (read and write) 7 = rwx (read, write and execute) I prefer that the group always have permission of 0. This prevents other users on the server from browsing files via Telnet and FTP. Here are the most common file permissions used: chmod 604 [filename] (minimum permission for www HTML file) chmod 705 [directoryname] (minimum permission for www directories) chmod 705 [filename] (minimum permission for www scripts & programs) chmod 606 [filename] (permission for datafiles used by www scripts) chmod 703 [directoryname] (write-only permission for public FTP uploading) Scheduling Tasks You can schedule tasks to run automatically by using the UNIX cron command. To use this, you create a text file with cron instructions, then process this file. cron instructions are basically UNIX commands with extra info about the time that they will run. One important thing to note is that it is best to use full paths when creating your cron file. As an example, create a file called mycronfile and in it place one line: 0 1 * * * cp /usr/www/file.txt /usr/www/backup.txt now at the command line, type the following: crontab mycronfile You have just scheduled an automated task! This task will run at the time specified until you decide you want to cancel it. There are six fields in this file. The first five represent the time that the job will run. The sixth field is a UNIX command that will run at the specified time. The above example will run every night at 1AM, at which time it will copy a file. Here is how the fields break down: Field 1 | Field 2 | Field 3 | Field 4 | Field 5 Minutes | Hours | Day of Month | Month | Day of Week (0-59) | (0-23) | (1-31) | (1-12) | (0-6) You can enter a number in the field, a range of numbers, or an * to indicate all. Here are a few more examples. These examples use the ls command, which would be pretty useless. Note the time that it runs, though. 0 1 * * 1-5 ls (this would run every Monday-Friday at 1am) 0 1 * * 1,3,5 ls (this would run every Monday, Wednesday and Friday at 1am) 10 2 1 * * ls (this would run at 2:10am on the first of every month) 0 1 1 1 * ls (this would run at 1am on January 1 every year) If you have a more complicated command that you want to run, it is sometimes helpful to create a shell script and have that script run. You specify the shell script as you would any UNIX command. For example: 0 1 * * * /usr/www/myscript There are some other crontab switches that are useful: crontab -l (lists your currently scheduled tasks) crontab -r (delete all currently scheduled tasks) crontab -e (directly edit your scheduled tasks)
Welcome to another year of cyber shopping at earthlingsunited. We organize and humanize access to shopping on the entire web, like no other portal on the web. Please don't forget to tell your friends about our special place. Thanks and enjoy your visit.
3.5 5/18/2001 12:45:33 0 16125 0
EarthlingsUnited .
About Us . Search
EarthlingsUnited . Customer Service .
Privacy
Copyright © 2000 All Rights Reserved