Problems with Perl/KSH Web Log Script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problems with Perl/KSH Web Log Script
# 1  
Old 05-03-2006
Problems with Perl/KSH Web Log Script

Hi,

I am writing a series of scripts for work to analyse intranet access logs. All of the scripts do as they should when run individually from the shell, but only when run from certain directories. This sounds like it may be a PATH issue but I am not sure. When I run a certain script, say "script.pl" from it's working directory - everything is fine. However, if I try to run the script from another location by specifying the full path name of the script, the script tries to execute and drops straight back to the shell without any output to the user. I do receive output if run from the working directory of the script.

The script is a Perl script, and I have the appropriate shebang line at the start of the file "#!/bin/perl". Also, the file has been CHMODed to execute.

Any help would be most appreciated.
Max
# 2  
Old 05-03-2006
Problem Solved

Thanks to anyone viewing my post. I seem to have solved the problem. I didn't think to export PATH in the ksh script that was calling my Perl scripts. I just added a PATH variable to the top of the script including any appropriate directories and exported that before I did anything else.

Thanks again.
# 3  
Old 05-03-2006
EDIT: It is nice that you figured out what went wrong. My original response follows, which describes another possibility within perl (although it turned out that you don't fall in that case).

--------------------------------------------------------------------------------------

This is in fact a BIG question.

This is a symptom that the script is not well written because it relies on being invoked from a certain working directory. This is a common problem that many scripts may work on the command line but refuse to run with cron, for instance, as the working directory is different from norm.

There is no easy fix to this problem if the script is written without the sense of such relocation in mind. A quick fix is by some simple compound command which "cd" and then execute the script (that you can always write a script to automate these two steps).

If you want to fix this permanently, you must examine the script line by line for all references with relative paths. They may occur as two major classes:

1. Operations depending on the Perl include path
2. File open() and external shell commands

The Perl include path (@INC) holds the list of directories to search for libraries (used by "require" and "use"). Make sure the dirs listed cover all the paths needed by your require() statements. If any of the items listed denote relative path, change them to use absolute paths. Normally, @INC includes '.', so the current working directory is taken into account.

Other file operations also depend on current working directory in case of relative paths are used. Without '/' prefix, all paths are relative to CWD. For instance,

open FILE, ">>file.txt";
`diff file1.txt file2.txt`

These two classes of relative paths should generally be treated separately, because they are of different nature. Perl @INC is for resolving external Perl scripts, they should not normally be subject to changes in CWD. However, at other times you may actually wish to honour the CWD in certain cases. For instance, in a build script one may wish to have compiled object binaries placed outside of the original source tree, so we will change the CWD to outside the tree and have everything generated dropped in that directory.

However, in really big scripts nobody wants to hardcode an absolute path everywhere (for portability/management sake as well). It is therefore common practice to have a single file that acts as a "configuration file" that defines all these paths in a centralized manner. The @INC is initialized at the start of the script based on the contents of this file. But then, how to locate this file? Either it is placed at a fixed location, or you may actually deduce dynamically the base directory of the current script file with something like

use File::Spec;
dirname(File::Spec->rel2abs(__FILE__))

as an aid to construct absolute paths from relative paths. If all of the paths are constructed without implicit use of relative paths, your script will then be independent of the CWD.

Tedious enough. Isn't it?
# 4  
Old 05-03-2006
That's fantastic - thank you for the very detailed response - always appreciated. If I have any further problems I will be sure to post...

Incidentally...

The next step I am having issues with is compressed files. For space reasons, the web logs that I am analysing are compressed nightly (they are typically in excess of 500Mb). If I wanted to uncompress these before performing any operations on them, would it just be a case of calling:

system(uncompress filename);

and then recompressing them in a similar fashion at the end? Or is it more involved fo you know?

Thanks for any help you can provide.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Web Automation in Perl/Ksh with NO additional modules

I would like to automate form filling in a remote way... i mean in the background. That form consists of 3 pages (need to be traversed by clicking on a "next" button). Form uses JavaScript as well. The scripts I have access to are perl/Unix shells I google'd and found that in perl it can be... (0 Replies)
Discussion started by: dahlia84
0 Replies

2. Shell Programming and Scripting

shell script to call perl script problems

Ok, don't ask me why, but all calls to perl must be called by a shell script. Its really not ideal, but its what I have to work with. Calling it isnt the issue, its passing in the arguments. I have about 1000 perl scripts to call by a shell script. Right now, I'm executing the shell script... (3 Replies)
Discussion started by: regexnub
3 Replies

3. Shell Programming and Scripting

Perl Script to find & copy words from Web.

I need to write a perl script to search for a specific set of numbers that occur after a series of words but before another. Specifically, I need to locate the phrase today at the summit, then immediately prior to the words tonnes/day copy the number that will be between 100 and 9,999, for example,... (1 Reply)
Discussion started by: libertyforall
1 Replies

4. Shell Programming and Scripting

Perl Print Problems in script

Hi Perl Gurus, perl -e 'print "http://www.site@domain.com"' The output of the above is : http://www.site.com" I want to print http://www.site@domain.com without using escape sequence before '@' like '\@'. Is there any way to do this in perl? Thanks, Som (1 Reply)
Discussion started by: som.nitk
1 Replies

5. Shell Programming and Scripting

Perl script to copy contents of a web page

Hi All, Sorry to ask this question and i am not sure whether it is possible. please reply to my question. Thanks in advance. I need a perl script ( or any linux compatible scripts ) to copy the graphical contents of the webpage to a word pad. Say for example, i have a documentation site... (10 Replies)
Discussion started by: anand.linux1984
10 Replies

6. UNIX for Dummies Questions & Answers

Downloading file from web using perl script

Hi experts, I've question in perl, i need to download a text file from the Web and save that content to the server, Is it possible in perl script or i need to do it in the excel. I tried in the excel but the alignment is missing there. Could you please help in find that. Thanks senthilkumar (0 Replies)
Discussion started by: senthil.ak
0 Replies

7. Shell Programming and Scripting

autosys/ksh - problems with script

Hi, I'm using autosys and want to set it up that I receive emails when certain jobs start and finish. I don't want to edit each jobs script (ksh) to send a mail at start and finish, I would rather have a single script/job that watches for a trigger when the jobs have started or finished. I... (1 Reply)
Discussion started by: weszardoz
1 Replies

8. Shell Programming and Scripting

Problems in running a Perl script via cronjob

I have a very basic perl script that attempts to find if a process is running. If the process is not running then the script is supposed to start the process. If I execute the script from command line it works fine as expected. However if the script is executed via cronjob, the script cannot find... (1 Reply)
Discussion started by: ypant
1 Replies

9. UNIX for Dummies Questions & Answers

Web Server - uploading Frontpage web - will there be problems??

hiya All, New to this Web site stuff. Will be installing Fedora's latest O/S (including Apache) - onto a spare PC Then... Gulp... setting up a Web server. Designing a Web site using WINDOWS FRONT PAGE 2002: * Simply easiest/quickiest way to knock up a basic site. * There won't be... (6 Replies)
Discussion started by: marty 600
6 Replies

10. UNIX for Dummies Questions & Answers

having ksh script problems

well i have written a script to telnet and ftp to all my servers, the script runs great, BUT i can not for the life of me figure out how to get the script to repeat if the conditions are not filled. this is what i have so far ######################################### TorF(){ echo T... (4 Replies)
Discussion started by: jerzey4life
4 Replies
Login or Register to Ask a Question