[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Articles, cont...
To you guys that are administering the system (and others too, but
especially you): If you come across a problem and then solve it, go
right ahead and write an article on it! It's fresh in your mind and
that's what we're here for. The minute you solve the problem is the
best time to write it up!
I'm going to try to write a couple more this week. I might be
interviewing for a cool Linux support job next week, and I want to be
able to show them I know something about Linux. :-)
In related news, here's an updated version of my previous article that
incorporates most of Roger's suggestions (thanks Roger):
------------------------------------
Problem: I'm trying to run a program or script named foo, and the shell
keeps telling me
"bash: foo: No such file or directory". foo does exist, and it is
executable. What gives?
Author: Micah Yoder
Version: 0.9.1
First, run file on the program or script in question to determine
whether it is a text or
binary executable file:
$ file foo
If you see ELF or a.out in the output, it's a machine executable
program. If not, it's
probably a script. We'll look at both cases.
If the file is a SCRIPT:
------------------------
Open the file foo with a text editor and look at the first line. If it
begins with #!, then
it could be referring to a nonexistent program, or one that is installed
in a different
place than expected. #! tells Linux to run the following program,
passing the name of
the executed file as an argument. If it can't find the specified
program, you will get
this error.
A common example is a Perl script that you get off a CD or from the
Web. Many script writers
assume Perl is installed in /usr/local/bin, so the script starts out
like this:
#!/usr/local/bin/perl
But most modern Linux distributions install Perl as /usr/bin/perl.
First, we need to be sure
our system has Perl, and find out where it is located. This is the
easiest way:
$ which perl
If the output is '/usr/bin/perl', or another location, then you're in
luck. You know Perl
is installed and you know where it is. If that doesn't work, Perl is
not in your path and
you will have to do some searching. Perhaps you have not installed it.
If you're sure you
have installed it, you can try this:
$ find / -name perl -print
Hopefully it will then print out the location of the Perl interpreter.
You can test it to
be sure:
$ /...path reported by find.../perl -e "print 'test'";
Note: If your case is not Perl, then simply attempt to run the command,
passing an argument
you expect it to like, for example, the filename of the script you're
trying to run.
Once you have determined the path of the program, you have three options
to fix the problem:
1. Edit the first line of the script so that it refers to the correct
path of the program.
It will require that you have permission to edit (write to) the script
file. If you do not
have write access to the file, copy it into your home directory and edit
it there.
2. Add a symbolic link that will make the script correct as it is.
This will require
that you have write permission to the directory pointed to by the
script. Here's how to
do it with our Perl example:
$ ln -s /usr/bin/perl /usr/local/bin/perl
The first argument is the actual path and filename and the second is
what follows #! in the
script.
3. Run the script by typing the correct full pathname of the program
referred to (you can leave
out the full pathname if the which command found it), followed by the
name of the script
as an argument:
$ /usr/bin/perl foo
$ perl foo
If the file is owned by root, you should probably talk to your system
administrator.
Other users could be having the problem as well, and the administrator
is the only
person who can fix it for everyone.
If the file is a BINARY:
------------------------
[Need to research this more] The program could be linked with a
nonexistent library,
or the wrong version of an existing one. Try:
$ ldd foo
and make sure no problems are reported. If you have the source code,
recompile it
on the same system.