Shell - cannot execute binary file

Shell - cannot execute binary file

am 23.11.2005 00:31:17 von Bhavesh Shah

Hi,
I am trying to run simple PATH or echo command in a file and try to
execute it fails with error:
cannot execute binary file
however it works for one user fail for another on the same Box.
If i force it to run in #! /bin/bash it does work. My concern is how
come it works for some users but fails for others?
Any help is greatly appreciated.
Regards
B

Cat testscript
bash-2.03$ cat testscript
PATH=/usr/local/bin/
bash-2.03$

bash-2.03$ ./testscript
bash: ./testscript: cannot execute binary file
bash-2.03$ . ./testscript
bash: .: ./testscript: cannot execute binary file

Re: Shell - cannot execute binary file

am 23.11.2005 00:47:35 von Lars Kellogg-Stedman

> I am trying to run simple PATH or echo command in a file and try to
> execute it fails with error:
> cannot execute binary file
> however it works for one user fail for another on the same Box.
> If i force it to run in #! /bin/bash it does work. My concern is how
> come it works for some users but fails for others?

You're getting the "cannot execute binary file" error because the system
doesn't know what to do with the file -- it's not actually a compiled
binary, and there's no "shebang" (#!) line telling it what interpreter
to use.

You should *always* start your shell scripts with a "#!" line specifying
that path to the appropriate interpreter. Some shells *will* try to
execute a file using /bin/sh if nothing else works, but that's not
something to depend on.

I'm guessing it works for one user because he/she is using a different
shell.

-- Lars

--
Lars Kellogg-Stedman <8273grkci8q8kgt@jetable.net>
This email address will expire on 2005-11-23.

Re: Shell - cannot execute binary file

am 23.11.2005 00:56:19 von Bhavesh Shah

> I'm guessing it works for one user because he/she is using a different
> shell.
>
No both users are having same bash shell nad it works for one and fails
for other. That is what i need to find out.

bash-2.03$ cat /etc/passwd | grep oracle
oracle:x:100:100:Oracle account:/home/oracle:/bin/bash
bash-2.03$ cat /etc/passwd | grep pnetops
pnetops:x:101:101:Pnetops account:/home/pnetops:/bin/bash

It works for user pnetops but fails for user oracle.

Re: Shell - cannot execute binary file

am 23.11.2005 04:10:33 von harryooopotter

tester wrote...
>
>Hi,
>I am trying to run simple PATH or echo command in a file and try to
>execute it fails with error:
>cannot execute binary file
>however it works for one user fail for another on the same Box.
>If i force it to run in #! /bin/bash it does work. My concern is how
>come it works for some users but fails for others?
>Any help is greatly appreciated.
>Regards
>B
>
>Cat testscript
>bash-2.03$ cat testscript
>PATH=/usr/local/bin/
>bash-2.03$
>
>bash-2.03$ ./testscript
>bash: ./testscript: cannot execute binary file
>bash-2.03$ . ./testscript
>bash: .: ./testscript: cannot execute binary file

What are the ownership and read/write/execute permissions of this
testscript?

ls -la /path/to/testscript

Re: Shell - cannot execute binary file

am 23.11.2005 09:58:03 von Thorsten Kampe

* tester (2005-11-22 23:56 +0100)
>> I'm guessing it works for one user because he/she is using a different
>> shell.
>>
> No both users are having same bash shell nad it works for one and fails
> for other. That is what i need to find out.
>
> bash-2.03$ cat /etc/passwd | grep oracle
> oracle:x:100:100:Oracle account:/home/oracle:/bin/bash
> bash-2.03$ cat /etc/passwd | grep pnetops

Get a grep right now, kid, before you get the Useless Use of cat
Award...

Re: Shell - cannot execute binary file

am 23.11.2005 10:08:42 von cfajohnson

On 2005-11-22, tester wrote:
> Hi,
> I am trying to run simple PATH or echo command in a file and try to
> execute it fails with error:
> cannot execute binary file
> however it works for one user fail for another on the same Box.
> If i force it to run in #! /bin/bash it does work. My concern is how
> come it works for some users but fails for others?

Are the locale setting different?

> Any help is greatly appreciated.
> Regards
> B
>
> Cat testscript
> bash-2.03$ cat testscript
> PATH=/usr/local/bin/
> bash-2.03$
>
> bash-2.03$ ./testscript
> bash: ./testscript: cannot execute binary file
> bash-2.03$ . ./testscript
> bash: .: ./testscript: cannot execute binary file

Add a blank line at the top of the file, and it should work for
everyone.

To see exactly what you have in the file, use od:

od -c testscript

--
Chris F.A. Johnson, author |
Shell Scripting Recipes: | My code in this post, if any,
A Problem-Solution Approach | is released under the
2005, Apress | GNU General Public Licence

Re: Shell - cannot execute binary file

am 23.11.2005 18:57:54 von Bill Marcum

On 22 Nov 2005 15:56:19 -0800, tester
wrote:
>
>> I'm guessing it works for one user because he/she is using a different
>> shell.
>>
> No both users are having same bash shell nad it works for one and fails
> for other. That is what i need to find out.
>
> bash-2.03$ cat /etc/passwd | grep oracle
> oracle:x:100:100:Oracle account:/home/oracle:/bin/bash
> bash-2.03$ cat /etc/passwd | grep pnetops
> pnetops:x:101:101:Pnetops account:/home/pnetops:/bin/bash
>
> It works for user pnetops but fails for user oracle.
>
Check the environment variables. Log in or "su -" as each user, do
the command "set > filename", and compare the contents of these files.


--
Power, n.:
The only narcotic regulated by the SEC instead of the FDA.

Re: Shell - cannot execute binary file

am 23.11.2005 23:08:57 von Bhavesh Shah

>
> Add a blank line at the top of the file, and it should work for
> everyone.

Thanks Chris. This Works. Thank u very much.

> To see exactly what you have in the file, use od:
>
> od -c testscript

Re: Shell - cannot execute binary file

am 23.11.2005 23:16:02 von Bhavesh Shah

> Get a grep right now, kid, before you get the Useless Use of cat
> Award...
Thanks for pointing that out actually my purpose was to solve the
problem.
Well efficient should have been:
grep "user" /etc/passwd.