The things I'll discuss here are aimed at new/intermediate perl coders that know basic *nix commands: ls,cd,chmod,chgrp,mv,cp, etc., meaning I'm not going to discuss these. I also assume you can use man and understand how to use telnet/ssh to get to your server. I realize that what I discuss here isn't specific to perl (or even CGI programming with perl) but is still (IMHO) very useful. If you want to know perl tricks to ease debugging, read the other tutorials in this section.

What I am going to discuss are a few *nix tricks/commands I've found that make my life MUCH easier when I'm debugging perl CGI scripts via a command console like telnet or ssh. I'll talk a little about screen, tab file/path name auto-completion, tail, and a couple others. These commands work in bash under Redhat 6.x and Mandrake, and probably many other distros or *nix flavors.

If you want to learn more, please read the man pages for any of these commands.

There are many other great unix tricks/commands that will help you in your perl coding. Hopefully the few that I've covered will be as useful to you as they are to me.

Comment on Easier Linux/Unix remote CGI Debugging
Select or Download Code
(jeffa) Re: Easier Linux/Unix remote CGI Debugging
by jeffa (Chancellor) on Apr 09, 2001 at 17:40 UTC
    Good stuff! I just wanted to stress the importance of adding the following line to your CGI script while debugging:
    use CGI::Carp qw(fatalsToBrowser); # You are using CGI, right?
    Now all fatal errors are echoed to the browser as well as the error log file. This is a must if you can't view the web server's error log. If that is the case, then perl -cw foo.cgi is also a must.

    Also, if you find yourself on a foreign ISP's box, having to fix someone's CGI script, and there is no /etc/httpd/logs/error_log, you can find which error log file is being used by Apache by searching through [path to apache root]/conf/httpd.conf

    Apache isn't always located in /etc/httpd/. When I install Apache on a box, I always install it in /usr/local/apache/. The mileage varies. :)

    Jeff

    R-R-R--R-R-R--R-R-R--R-R-R--R-R-R--
    L-L--L-L--L-L--L-L--L-L--L-L--L-L--
    

      Jeffa,
      Thanks for the thoughts! Maybe I should put the locate command in here too (of course root needs to create the locate db and allow other users to access it), you can just do locate filename on many boxes to find a file (like error_log).

      The reason I didn't put in to use CGI::Carp qw(fatalsToBrowser); (something that I use all the time) was because I thought I'd focus this tutorial around *nix commands that help you with remote perl debugging/coding, and leave the perl tricks to more experienced monks.

      I thought I might be good to separate *nix tricks from perl debugging tricks in general, in an effort to make Perlmonks more non-*nix friendly.

(crazyinsomniac: more portability) Re: Easier Linux/Unix remote CGI Debugging
by crazyinsomniac (Prior) on Apr 09, 2001 at 18:04 UTC
    How about making this guide a bit more usefull. I'm sure you've seen this code before:
    BEGIN {#outputs al errors to use CGI::Carp qw(carpout); open(LOG, ">>myScript.err.log") or die "can't W 2 myScript.cgi.err.l +og: $!"; carpout(*LOG); }

     
    ___crazyinsomniac_______________________________________
    Disclaimer: Don't blame. It came from inside the void

    perl -e "$q=$_;map({chr unpack qq;H*;,$_}split(q;;,q*H*));print;$q/$q;"