linux - execl: couldn't exec `/bin/sh'
2014-07
I accidentally moved the whole bin, boot, dev and etc directory. After moving everything back I get the following error email from various cron jobs:
execl: couldn't exec `/bin/sh'
execl: No such file or directory
Command used to move the directories:
mv /* /some-folder
ls -l /bin/sh
lrwxrwxrwx 1 root root 4 Jul 22 2013 /bin/sh -> bash
ls -l /bin/bash
-rwxr-xr-x 1 root root 938832 Jul 18 2013 /bin/bash
I look to see where the command is located:
xxx:~/mono/mono-2.6.7$ which mono
/usr/local/bin/mono
If I execute it directly, no problem:
xxx:~/mono/mono-2.6.7$ /usr/local/bin/mono -V
Mono JIT compiler version 2.6.7 (tarball Mon Aug 2 16:01:50 UTC 2010)
Copyright (C) 2002-2010 Novell, Inc and Contributors. www.mono-project.com
....
But if I execute the command without the path it cannot find it:
xxx:~/mono/mono-2.6.7$ mono
bash: /usr/bin/mono: No such file or directory
There is no mono file in /usr/bin:
xxx:~/mono/mono-2.6.7$ ls -l /usr/bin/mono
ls: cannot access /usr/bin/mono: No such file or directory
Here is my path:
xxx:~/mono/mono-2.6.7$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
Doesn't it search each directory separated by the colons? So shouldn't it find mono in /usr/local/bin ?
If I log in as root, it works. I can execute mono on the command line and it finds it. The permissions are:
xxx:~/mono/mono-2.6.7$ ls -l /usr/local/bin/mono
-rwxr-xr-x 1 root root 8452592 2010-08-02 16:23 /usr/local/bin/mono
Is the user I am using not part of the right group?
Bash keeps a cache of command locations in memory, so that it doesn't have to do the whole PATH exploration each time you start a command. In your original bash session, bash had previously memorized that mono
was /usr/bin/mono
. Then you removed /usr/bin/mono
and added /usr/local/bin/mono
, but your running bash still had the old location in its cache.
You can manipulate the command location cache with the hash
builtin. In particular hash -r
clears the cache.
which
is an external command, so it doesn't use bash's cache and performs a PATH lookup every time. You could also have used type
, which is a builtin and therefore does use the lookup cache.
Maybe you have an alias defined for mono? Check out that the following files in your home directory: .bashrc, .profile, .login or *.bash_profile*
... does not contain something like this
alias mono="/usr/bin/mono"
This can also be located in /etc/bashrc or /etc/profile.
Command alias shows all currently defined aliases.
I logged out, and then logged in again and it worked. I must have been doing something stupid. But, it works!