Different results Command Line/CGI

Ask a Question related to PERL Beginners, Design and Development.

  1. #1

    Default Different results Command Line/CGI


    I have this script stolen and modified from somewhere

    #!/usr/bin/perl -w
    use strict;
    use File::Find;
    print "Content-type: text/html\n\n";

    my $u=shift;
    my $sizes = 0;
    # replace this with your absolute path
    my $path = "/home/$u/";

    find (sub {$sizes += -s ;}, $path);
    print "$sizes\n";


    I am logged onto my machine as user owen and am root. From the command line I execute

    perl /var/www/cgi-bin/ff1.cgi owen with the result

    --------------------------
    Content-type: text/html

    (warnings snipped)

    504137000
    ---------------------------

    with rcook as the user in /home the result is 988865

    Now when I do 'links [url]http://localhost/cgi-bin/ff1.cgi?owen[/url]'

    the result is 350200607 (vs 504137000 ???) and
    for user rcook the result is 0 (vs 988865)

    du gives me yet another set of answers as does other File::Find type programs I have found, but that is not the problem at the moment.

    Why do I get 0 for rcook when I run it through the browser?
    I suspect the difference is something to do with permissions of the cgi script when run as a cgi script but do not know.



    Any advice/clues would be most welcome


    TIA

    --
    Owen

    Owen Guest

  2. Similar Questions and Discussions

    1. How do I get to the command line?
      I just loaded UBUNTU on a machine, and I need to load an NVIDIA driver. The instructions tell me to type "sh NVIDIA...", but I cannot find a way...
    2. command-line
      hey guys, i'm trying to grep some data from a log file and getting the following error. Any ideas??? $ perl -e 'grep \"Eliminating movie\"...
    3. RUN/execute a Command-Line command from an ASP page
      Hi, I need to RUN/execute a Command-Line command from an ASP page. This is the command: sse45.exe -i k:\o\2.wmv -o k:\o\2.shh -w 128 -df 0 -m 2...
    4. RUN/execute a Command-Line command from an ASP page.
      Hi, I need to RUN/execute a Command-Line command from an ASP page. This is the command: sse45.exe -i k:\o\2.wmv -o k:\o\2.shh -w 128 -df 0 -m 2...
    5. command line in OS 8.5
      Hello, I need your help. I have a G3 Desktop at work with OS 8.5 (german version). There seems to be some weird keystroke combination that...
  3. #2

    Default Re: Different results Command Line/CGI

    Owen wrote:
    > I have this script stolen and modified from somewhere
    >
    > #!/usr/bin/perl -w
    > use strict;
    > use File::Find;
    > print "Content-type: text/html\n\n";
    >
    > my $u=shift;
    > my $sizes = 0;
    > # replace this with your absolute path
    > my $path = "/home/$u/";
    >
    > find (sub {$sizes += -s ;}, $path);
    > print "$sizes\n";
    >
    >
    > I am logged onto my machine as user owen and am root.
    That is percisely why.




    From the command line I execute
    >
    > perl /var/www/cgi-bin/ff1.cgi owen with the result
    >
    > --------------------------
    > Content-type: text/html
    >
    > (warnings snipped)
    >
    > 504137000
    > ---------------------------
    >
    > with rcook as the user in /home the result is 988865
    >
    > Now when I do 'links [url]http://localhost/cgi-bin/ff1.cgi?owen[/url]'
    >
    > the result is 350200607 (vs 504137000 ???) and
    > for user rcook the result is 0 (vs 988865)
    >
    > du gives me yet another set of answers as does other File::Find type programs I have found, but that is not the problem at the moment.
    >
    > Why do I get 0 for rcook when I run it through the browser?
    > I suspect the difference is something to do with permissions of the cgi script when run as a cgi script but do not know.
    >
    >
    >
    > Any advice/clues would be most welcome
    >
    >
    > TIA
    >


    Your web server may not be running as user root and therefore it may not
    have permissions to go to all directories.
    Hence you would get a zero

    Ram

    Ramprasad A Padmanabhan Guest

  4. #3

    Default RE: Different results Command Line/CGI


    > I have this script stolen and modified from somewhere
    Stealling is bad! :)
    >
    > #!/usr/bin/perl -w
    > use strict;
    > use File::Find;
    > print "Content-type: text/html\n\n";
    >
    > my $u=shift;
    > my $sizes = 0;
    > # replace this with your absolute path
    > my $path = "/home/$u/";
    >
    > find (sub {$sizes += -s ;}, $path);
    > print "$sizes\n";
    >
    >
    > I am logged onto my machine as user owen and am root. From
    > the command line I execute
    >
    > perl /var/www/cgi-bin/ff1.cgi owen with the result
    >
    > --------------------------
    > Content-type: text/html
    >
    > (warnings snipped)
    >
    > 504137000
    > ---------------------------
    >
    > with rcook as the user in /home the result is 988865
    >
    > Now when I do 'links [url]http://localhost/cgi-bin/ff1.cgi?owen[/url]'
    >
    > the result is 350200607 (vs 504137000 ???) and
    > for user rcook the result is 0 (vs 988865)
    >
    Permissions Permissions Permissions:

    The user the webserver is runnign at obvioulsy doesn't have
    permissions to "see" all the files that the user you where
    logged in as did. And it is not allowed to see the rcook directory at
    all aparently.

    HTH

    Dmuey
    Dan Muey Guest

  5. #4

    Default How to call perl with in-line contents?

    Hi All,

    I have a file with the following contents (temp.txt).
    A1110
    G1115
    B1110
    C1111
    D1111
    E1113
    F1115
    and so on. I have to read the contents from this file and create 2
    seperate files. The 1st file contains the lines ending with 0 and 1
    while the 2nd file contains the lines ending with 3 and 5. I can do this
    easily by creating a seperate perl script. But I have a constraint. I
    should not write a seperate file to do this processing.

    I am calling the perl from a shell script. Is there any way of calling
    the Perl program "in-line" with all the required parameters? "In-line"
    means no seperate file containing the script.

    Is it worth doing this? Is there a better way of doing it?

    Regards,
    Vishal Vasan.
    Vishal Vasan Guest

  6. #5

    Default Re: How to call perl with in-line contents?

    On Feb 13, 2004, at 6:24 AM, Vishal Vasan wrote:
    > Hi All,
    >
    > I have a file with the following contents (temp.txt).
    > A1110
    > G1115
    > B1110
    > C1111
    > D1111
    > E1113
    > F1115
    > and so on. I have to read the contents from this file and create 2
    > seperate files. The 1st file contains the lines ending with 0 and 1
    > while the 2nd file contains the lines ending with 3 and 5. I can do
    > this easily by creating a seperate perl script. But I have a
    > constraint. I should not write a seperate file to do this processing.
    >
    > I am calling the perl from a shell script. Is there any way of calling
    > the Perl program "in-line" with all the required parameters? "In-line"
    > means no seperate file containing the script.
    >
    > Is it worth doing this? Is there a better way of doing it?
    Is there a reason not to just use a Perl script, instead of a shell
    script? We can definitely do all the work in one Perl script.

    #!/usr/bin/perl

    use strict;
    use warnings;

    die "Usage: perl script_name INPUT_FILE_NAME\n" unless @ARGV;
    my $file = shift;
    open INPUT, '<', $file or die "File error: $!";
    open SMALLOUT, '>', "01$file" or die "File error: $!";
    open BIGOUT, '>', "2+$file" or die "File error: $!";

    while (<INPUT>) {
    chomp;
    if (/[01]\s*$/) { print SMALLOUT "$_\n"; }
    else { print BIGOUT "$_\n"; }
    }

    close INPUT;
    close SMALLOUT;
    close BIGOUT;

    __END__

    Hope that helps.

    James

    James Edward Gray II Guest

  7. #6

    Default Re: How to call perl with in-line contents?

    On Fri, 13 Feb 2004 17:54:54 +0530
    Vishal Vasan <vishal.v@net-kraft.com> wrote:
    > Hi All,
    >
    > I have a file with the following contents (temp.txt).
    > A1110
    > G1115
    > B1110
    > C1111
    > D1111
    > E1113
    > F1115
    > and so on. I have to read the contents from this file and create 2
    > seperate files. The 1st file contains the lines ending with 0 and 1
    > while the 2nd file contains the lines ending with 3 and 5. I can do
    > this easily by creating a seperate perl script. But I have a
    > constraint. I should not write a seperate file to do this processing.
    >
    > I am calling the perl from a shell script. Is there any way of calling
    >
    > the Perl program "in-line" with all the required parameters? "In-line"
    >
    > means no seperate file containing the script.
    >
    > Is it worth doing this? Is there a better way of doing it?
    You can do all the stuff in one perl-script. You can just put it on top
    of the data:

    #!/path/to/perl -w

    # Your perl-code goes here

    DATA

    A1110
    G1115
    B1110
    C1111
    D1111
    E1113
    F1115
    ....

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

    Then you can treat the file's content after the line

    DATA

    as a file by using the filehandle <DATA> to read from it.


    Kind regards,

    Benjamin
    Benjamin Walkenhorst Guest

  8. #7

    Default Re: How to call perl with in-line contents?

    On Fri, 13 Feb 2004, Vishal Vasan wrote:
    > Hi All,
    >
    > I have a file with the following contents (temp.txt).
    > A1110
    > G1115
    > B1110
    > C1111
    > D1111
    > E1113
    > F1115
    > and so on. I have to read the contents from this file and create 2
    > seperate files. The 1st file contains the lines ending with 0 and 1
    > while the 2nd file contains the lines ending with 3 and 5. I can do this
    > easily by creating a seperate perl script. But I have a constraint. I
    > should not write a seperate file to do this processing.
    >
    > I am calling the perl from a shell script. Is there any way of calling
    > the Perl program "in-line" with all the required parameters? "In-line"
    > means no seperate file containing the script.
    >
    > Is it worth doing this? Is there a better way of doing it?
    >
    > Regards,
    > Vishal Vasan.
    This may be hearsy here on the Perl list, but is Perl the best choice in
    this case? If I had to imbed this in a shell script, I'd use grep twice.

    grep '[01]$' input.file >output.file.01
    grep '[35]$' input.file >output.file.35

    --
    Maranatha!
    John McKown

    John McKown Guest

  9. #8

    Default Re: How to call perl with in-line contents?

    The "deep" opinions are interspersed with your original message. An in-line
    (pardon the "win32-ish-ness" quote escaping) could take the form:

    perl -ne "BEGIN{open S, '>smf';open L, '>lgf'} chomp;if (/[01]\s*$/){print
    S \"$_\n\";}else{print L \"$_\n\";}" f1.txt

    where your data is in f1.txt, your "0" or "1" ending lines go into "smf",
    and the others go into "lgf"

    At 05:54 PM 2/13/04 +0530, you wrote:
    >Hi All,
    >
    >I have a file with the following contents (temp.txt).
    >A1110
    >G1115
    >B1110
    >C1111
    >D1111
    >E1113
    >F1115
    >and so on. I have to read the contents from this file and create 2
    >seperate files. The 1st file contains the lines ending with 0 and 1 while
    >the 2nd file contains the lines ending with 3 and 5. I can do this easily
    >by creating a seperate perl script. But I have a constraint. I should not
    >write a seperate file to do this processing.
    >
    >I am calling the perl from a shell script. Is there any way of calling the
    >Perl program "in-line" with all the required parameters? "In-line" means
    >no seperate file containing the script.
    >
    >Is it worth doing this?
    Only your boss and the deadline knows for sure
    >Is there a better way of doing it?
    As always, yes. That's the cool part about this language, but don't take
    more than 3 minutes... ;-)

    >Regards,
    >Vishal Vasan.
    >
    >--
    >To unsubscribe, e-mail: [email]beginners-unsubscribe@perl.org[/email]
    >For additional commands, e-mail: [email]beginners-help@perl.org[/email]
    ><http://learn.perl.org/> <http://learn.perl.org/first-response>
    >
    Tim Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139