newbie question: can't get script to execute

L

lkrubner

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"?
 
T

Tim Heaney

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
 
S

Sherm Pendley

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--
 
T

Tim Heaney

Sherm Pendley said:
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
 
S

Sherm Pendley

Tim Heaney said:
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:

sherm--
 
L

lkrubner

Sherm said:
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.


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.



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.




Why did you expect different results?

I don't know. Desperation I gues.



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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top