newbie question: can't get script to execute

Discussion in 'Perl Misc' started by lkrubner@geocities.com, Oct 15, 2005.

  1. Guest

    I saw this script on O'Rielly:

    http://www.perl.com/pub/a/2002/08/20/perlandlwp.html

    I was wondering if I could get it to work on my machine, so I installed
    and tried to run it. I saved this in a script "process.bsh".

    #!/usr/bin/perl -w
    my $url = 'http://www.bluewallllc.com/hi.php';
    use LWP::Simple;
    my $content = get $url;
    die "Couldn't get $url" unless defined $content;
    print "The total was: \n";
    print $content;


    I get "cannot execute". I chmod to 777 and still get "cannot execute".
    I am logged in as root. I switched from the bash shell to the korn
    shell and got the same results.

    I'm wondering, do I need to save this file with a ".pl" ending? If LWP
    is not there on my server, I'll get an error message, yes? Something
    more than "cannot execute"?
     
    , Oct 15, 2005
    #1
    1. Advertising

  2. Tim Heaney Guest

    writes:

    > I saw this script on O'Rielly:
    >
    > http://www.perl.com/pub/a/2002/08/20/perlandlwp.html
    >
    > I was wondering if I could get it to work on my machine, so I installed
    > and tried to run it. I saved this in a script "process.bsh".
    >
    > #!/usr/bin/perl -w
    > my $url = 'http://www.bluewallllc.com/hi.php';
    > use LWP::Simple;
    > my $content = get $url;
    > die "Couldn't get $url" unless defined $content;
    > print "The total was: \n";
    > print $content;
    >
    >
    > I get "cannot execute". I chmod to 777 and still get "cannot execute".
    > I am logged in as root. I switched from the bash shell to the korn
    > shell and got the same results.
    >
    > I'm wondering, do I need to save this file with a ".pl" ending? If LWP
    > is not there on my server, I'll get an error message, yes? Something
    > more than "cannot execute"?


    That's probably your shell complaining that it cannot execute
    /usr/bin/perl, rather than Perl complaining that it cannot execute
    your code. Try running perl explicitly

    perl process.bsh

    If that works do a

    which perl

    to see where it is and put that on the first line with the #!. After
    that you should be able to just run

    process.bsh

    No, you don't need to end the file with .pl. Yes, you should get a
    more informative error message if Perl cannot find something.

    I hope this helps,

    Tim
     
    Tim Heaney, Oct 15, 2005
    #2
    1. Advertising

  3. writes:

    > I was wondering if I could get it to work on my machine, so I installed
    > and tried to run it. I saved this in a script "process.bsh".


    Why? The typical name for a shell script it .sh, and this is not a shell
    script. That's not the problem though, just a potential source of confusion
    for the user later.

    > #!/usr/bin/perl -w
    > my $url = 'http://www.bluewallllc.com/hi.php';
    > use LWP::Simple;
    > my $content = get $url;
    > die "Couldn't get $url" unless defined $content;
    > print "The total was: \n";
    > print $content;
    >
    > I get "cannot execute".


    Literally, those two exact words and nothing else? I have doubts...

    > I chmod to 777 and still get "cannot execute".


    What did you expect to accomplish by allowing anyone on your system to
    alter your script?

    > I am logged in as root.


    Why? Nothing in the script you're running needs root authority.

    > I switched from the bash shell to the korn
    > shell and got the same results.


    Why did you expect different results?

    > I'm wondering, do I need to save this file with a ".pl" ending?


    Not simply to run it from a shell prompt, no. The OS uses the first #!
    line of a script to determine what interpreter to run it with; you could
    use any extension, or none at all.

    Having said that, it's still a good idea to use a .pl extension. With a
    ..pl extension you can see immediately what it is, when you return to the
    task next year having completely forgotten about it. And, if you're using
    a desktop environment such as Gnome, KDE, or Mac OS X, the extension can
    be associated to a double-click event, such as opening the file in your
    favorite editor.

    > If LWP
    > is not there on my server, I'll get an error message, yes? Something
    > more than "cannot execute"?


    Yes. In fact, in every scenario I can imagine where a script cannot be
    run for some reason, you get more than those two words. For instance, if
    I misspell the name of the interpreter, I get:

    -bash: ./bogus.pl: /usr/bin/pearl: bad interpreter: No such file or directory

    If the script lacks execute permission, I get:

    -bash: ./bogus.pl: Permission denied

    If the interpreter lacks execute permission, I get:

    -bash: ./bogus.pl: /usr/bin/perl: bad interpreter: Permission denied

    If there's a syntax error, I get:

    String found where operator expected at ./bogus.pl line 3, near "orint "Howdy, world!\n""
    (Do you need to predeclare orint?)
    syntax error at ./bogus.pl line 3, near "orint "Howdy, world!\n""
    Execution of ./bogus.pl aborted due to compilation errors.

    See where this is going? In every case, the error message is distinct and far
    more descriptive than a cryptic two-word "cannot execute". If that's really
    the complete message that you're seeing, please let me know what OS you're
    using, so I can avoid it. ;-)

    Otherwise, post the actual message - copy and paste it, don't try to re-type
    and/or summarize it. (This is mentioned in the posting guidelines for this
    group, by the way. Have you read them?)

    sherm--

    --
    Cocoa programming in Perl: http://camelbones.sourceforge.net
    Hire me! My resume: http://www.dot-app.org
     
    Sherm Pendley, Oct 15, 2005
    #3
  4. Tim Heaney Guest

    Sherm Pendley <> writes:

    > writes:
    >
    >> If LWP
    >> is not there on my server, I'll get an error message, yes? Something
    >> more than "cannot execute"?

    >
    > Yes. In fact, in every scenario I can imagine where a script cannot be
    > run for some reason, you get more than those two words.


    I think perhaps you've been spoiled by that fancy bash shell of
    yours. Not every shell is so helpful

    $ ksh
    $ process.bsh
    ksh: process.bsh: cannot execute
    $ csh
    $ process.bsh
    process.bsh: Command not found.

    While you're technically correct, he got more than those two words,
    I'd hesitate to blame the OP for being baffled by either of these.

    Tim
     
    Tim Heaney, Oct 15, 2005
    #4
  5. Tim Heaney <> writes:

    > Sherm Pendley <> writes:
    >
    >> writes:
    >>
    >>> If LWP
    >>> is not there on my server, I'll get an error message, yes? Something
    >>> more than "cannot execute"?

    >>
    >> Yes. In fact, in every scenario I can imagine where a script cannot be
    >> run for some reason, you get more than those two words.

    >
    > I think perhaps you've been spoiled by that fancy bash shell of
    > yours.


    The OP said he got the same result in both bash and ksh:

    >>> I get "cannot execute". I chmod to 777 and still get "cannot execute".
    >>> I am logged in as root. I switched from the bash shell to the korn
    >>> shell and got the same results.


    sherm--

    --
    Cocoa programming in Perl: http://camelbones.sourceforge.net
    Hire me! My resume: http://www.dot-app.org
     
    Sherm Pendley, Oct 16, 2005
    #5
  6. Guest

    Sherm Pendley wrote:
    > >
    > > I get "cannot execute".

    >
    > Literally, those two exact words and nothing else? I have doubts...


    Yes, believe me, just those two words and nothing else. The person I
    was working with, who knows unix much better than I, was quite
    surprised.



    > > I chmod to 777 and still get "cannot execute".

    >
    > What did you expect to accomplish by allowing anyone on your system to
    > alter your script?


    Only two people have access to the script right now, and I was trying
    to debug it.




    > > I am logged in as root.

    >
    > Why? Nothing in the script you're running needs root authority.


    Because I don't know what I'm doing and I was trying anything I could
    think of.





    > > I switched from the bash shell to the korn
    > > shell and got the same results.

    >
    > Why did you expect different results?


    I don't know. Desperation I gues.




    > > If LWP
    > > is not there on my server, I'll get an error message, yes? Something
    > > more than "cannot execute"?

    >
    > Yes. In fact, in every scenario I can imagine where a script cannot be
    > run for some reason, you get more than those two words. For instance, if
    > I misspell the name of the interpreter, I get:
    > See where this is going? In every case, the error message is distinct and far
    > more descriptive than a cryptic two-word "cannot execute". If that's really
    > the complete message that you're seeing, please let me know what OS you're
    > using, so I can avoid it. ;-)


    My apologies. I misspoke. We were using one shell, I don't know which,
    and then switched to the korn shell. I don't think we used the bash
    shell. The system we were on was running HP Unix.
     
    , Oct 16, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. spec
    Replies:
    7
    Views:
    75,315
    Cameron Laird
    Jul 18, 2006
  2. johnny
    Replies:
    5
    Views:
    545
    Antonio Cuni
    Jul 11, 2007
  3. Rajat
    Replies:
    3
    Views:
    730
    Jorgen Grahn
    Jan 8, 2010
  4. VYAS ASHISH M-NTB837
    Replies:
    2
    Views:
    589
    Jan Kaliszewski
    Jan 7, 2010
  5. Savas Ates
    Replies:
    1
    Views:
    298
    Patrice
    Aug 17, 2004
Loading...

Share This Page