How can I resolve the error "cannot execute binary file"?
Usually that error message means Linux doesn't recognize the file as a shell script or as an executable file.
Typically the cause is running an executable on the wrong architecture - if you try to run x86 executables on an ARM CPU, this message comes up.
Did /usr/bin/id
get overwritten, possibly?
Try to run it using ./executablefilename instead of using sh executablefilename. It's not a shell script after all.
The problem is running a binary for a different processor architecture. You can use objdump (from binutils) to check architecture of binaries. You can use uname to check architecture of a machine.
e.g. I encountered this error "cannot execute binary file" when installing FF.Communicator - a firefox plugin for chrome (so I can run pages that use java applets).
- objdump shows the binary is 64-bit elf64-x86-64
-
uname shows my machine is 32-bit i686
$ ./FF.Communicator bash: ./FF.Communicator: cannot execute binary file $ uname -mpio i686 i686 i386 GNU/Linux $ objdump -a ./FF.Communicator ./FF.Communicator: file format elf64-x86-64 ./FF.Communicator
-
objdump on a working binary on my machine shows it is 32-bit elf32-i386
$ objdump -a /bin/ls /bin/ls: file format elf32-i386
Using these tools you can check architectures of machines and binaries - not just intel architectures but any processor.
For Mac OSX users, you can find out the architecture info of a specific file using the "file" command:
$ file filename_here
I'm making some wild guesses here, but it looks like the following is happening:
- You log in over SSH, triggering
bash
to run your~/.profile
or~/.bashrc
to set up your environment for you (this is normal). - At some point it tries to execute
/bin/id
to get your uid, which fails, causing integer expression error, and terminating the script before it can set up your$PATH
. - Because your
$PATH
is not set, bash is only able to run commands with the full path specified.
Use export PATH=/bin:/usr/bin:/sbin:/usr/sbin
to fix the $PATH
issue until you can fix the root cause of /bin/id failing.
This means that you are trying to execute a binary file using your bash script which is not intended to be run as you trying it to be. It is already a binary file and you are trying your $SHELL to parse and run it.
in a very simple example, if you try to run `w' command like
$ bash w
/usr/bin/w: /usr/bin/w: cannot execute binary file
similarly you might be hitting the same method or as it looks from your code snippet.
While , for the remaining for your commands, Al these halt, shutdown , reboot etc commands are the root owned commands and need super-user prilveges to run and perform the required operation. normal users can't run them another explanation is that these commands are placed at /sbin/ and /usr/sbin , which might not be in your $PATH variable ( which is used to validate commands in your custody )