LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-09-2015, 08:26 AM   #1
aavika
Member
 
Registered: Dec 2014
Posts: 82

Rep: Reputation: Disabled
cannot execute binary file


hello everyone,
I created a script file (info.sh) in linux centos 6.
location of file is '/etc/init.d/info.sh'
content of file is:

#!/bin/sh
#To get the MAC address
ifconfig | grep HWaddr
#To get the HDD serial no.
hdparm -I /dev/sd? | grep 'Serial\ Number'
#To get the HDD size
hdparm -I /dev/sda |grep "device size"

gave the permission by: chmod 777 /etc/init.d/info.sh
but when i run this file by: /etc/init.d/info.sh
it gives an error like...
-bash: /etc/init.d/info: cannot execute binary file

what should i do?? Actually i have to run this file during boot up..

thanks in advance..
 
Old 04-09-2015, 08:35 AM   #2
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
Quote:
Originally Posted by aavika View Post
hello everyone,
I created a script file (info.sh) in linux centos 6.
location of file is '/etc/init.d/info.sh'
content of file is:

#!/bin/sh
#To get the MAC address
ifconfig | grep HWaddr
#To get the HDD serial no.
hdparm -I /dev/sd? | grep 'Serial\ Number'
#To get the HDD size
hdparm -I /dev/sda |grep "device size"

gave the permission by: chmod 777 /etc/init.d/info.sh
but when i run this file by: /etc/init.d/info.sh
it gives an error like...
-bash: /etc/init.d/info: cannot execute binary file

what should i do?? Actually i have to run this file during boot up..

thanks in advance..
seems like theres a typo somewhere ?
 
Old 04-09-2015, 09:12 AM   #3
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
First, it should not be mode 777. At most it could be 755. Having world write access would allow anyone to change the file... and be able to gain root access when it is run by root - at boot time or any other time.

Next, for it to be run at boot time, you might check the security labels of other scripts... If the script doesn't have the proper label it can't be executed.

this changes in CenOS 7, I believe the security label changes to help isolate boot utilties from introducing security failures (which would be caused by having world write access).
 
Old 04-09-2015, 12:05 PM   #4
aavika
Member
 
Registered: Dec 2014
Posts: 82

Original Poster
Rep: Reputation: Disabled
Okay 755 chmod
Boot up is 2nd or final stage
Firstly I have to run manually..
And its givin me same error even manually
Is there any code error? Or syntax and all...

---------- Post added 04-09-15 at 12:05 PM ----------

Okay 755 chmod
Boot up is 2nd or final stage
Firstly I have to run manually..
And its givin me same error even manually
Is there any code error? Or syntax and all...
 
Old 04-09-2015, 12:06 PM   #5
aavika
Member
 
Registered: Dec 2014
Posts: 82

Original Poster
Rep: Reputation: Disabled
Okay 755 chmod
Boot up is 2nd or final stage
Firstly I have to run manually..
And its givin me same error even manually
Is there any code error? Or syntax and all...
 
Old 04-09-2015, 12:35 PM   #6
zeebra
Senior Member
 
Registered: Dec 2011
Distribution: Slackware
Posts: 1,833
Blog Entries: 17

Rep: Reputation: 640Reputation: 640Reputation: 640Reputation: 640Reputation: 640Reputation: 640
I am not sure what the problem is here exactly, and not figuring out exactly what you have done.

Did you do chmod +x ?
Are you the owner of the file? Or better yet, depending on the distro, is the "user" allowed to run "hdparm" and the script?

What are you trying to accomplish exactly? With the script...

Do you run it at boot or want to run it manually by typing in "sh script.sh" or "./script.sh"..


As you probably see, I dont work much with scripts, but this should be the same as a C compiled file in practice, yes?
 
Old 04-09-2015, 01:10 PM   #7
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
It should run fine interactively. If not, you can use the "-vx" option to turn on verbose messages.

The only executable (to start with) is /bin/sh, so that has to exist. One thing - depending on the location of the shell script: If it is a partition mounted with noexec, then you would get the error message you are getting.

I don't have a handy CentOS 6 system, but it should be linked to /bin/bash.

The other commands could be a problem if the PATH environment is not what the script expects, but that depends on WHEN it gets executed. A script like this would be running from rc.local.

NOTE: output to stdout will not be visible as the console terminals are not set up. Redirections to /dev/console should go to what is currently the console (and show in logs), but may also not be visible (depends on version - I think there is/will be a problem with CentOS 7, but I don't have it running at the moment either).
 
Old 04-09-2015, 11:58 PM   #8
aavika
Member
 
Registered: Dec 2014
Posts: 82

Original Poster
Rep: Reputation: Disabled
Centos 6,
i want to make a script file to read MAC address and hdd no. and size, which should be run during boot up of the linux machine.
thats y i put the file in '/etc/rc.d/init.d/info.sh' file name is 'info.sh'

i did chmod +x /etc/rc.d/init.d/info.sh
chmod 755 /etc/rc.d/init.d/info.sh

just for testing to make sure that it's working properly or givin perfect output, i want to run it manually...
after that i will check at the time of booting.

all commands of info.sh file is working perfectly.. no doubt because each and every command i checked manually by typing in linux terminal..

thanks for the reply..
 
Old 04-10-2015, 12:05 AM   #9
veerain
Senior Member
 
Registered: Mar 2005
Location: Earth bound to Helios
Distribution: Custom
Posts: 2,524

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319
Did you checked it's permissions after chmod +x.

Code:
ls -l /etc/rc.d/init.d/info.sh
Has it changed to executable permissions?

May be /etc is getting mounted with noexec option.

Code:
cat /proc/mounts | grep etc
 
Old 04-10-2015, 12:21 AM   #10
aavika
Member
 
Registered: Dec 2014
Posts: 82

Original Poster
Rep: Reputation: Disabled
ya.. just i checked with the command: ls -l /etc/rc.d/init.d/info.sh

output: -rwxr-xr-x 1 root root 2430 Apr 10 10:45 /etc/rc.d/init.d/info.sh

then i wrote: sh /etc/rc.d/init.d/info.sh

output: /etc/rc.d/init.d/info.sh: /etc/rc.d/init.d/info.sh: cannot execute binary file

what should i do?
 
Old 04-10-2015, 02:31 AM   #11
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,930

Rep: Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321
you can try sh -xv /etc/rc.d/init.d/info.sh to check what's happening.
 
Old 04-14-2015, 11:01 AM   #12
zeebra
Senior Member
 
Registered: Dec 2011
Distribution: Slackware
Posts: 1,833
Blog Entries: 17

Rep: Reputation: 640Reputation: 640Reputation: 640Reputation: 640Reputation: 640Reputation: 640
So, in bash, when you try to just run it manually, you just type "sh scriptname.sh" with the regular user account? Or with root? Or with Sudo?

Centos should also be Systemd? Who invokes the script when?
 
Old 04-14-2015, 09:02 PM   #13
sgosnell
Senior Member
 
Registered: Jan 2008
Location: Baja Oklahoma
Distribution: Debian Stable and Unstable
Posts: 1,943

Rep: Reputation: 542Reputation: 542Reputation: 542Reputation: 542Reputation: 542Reputation: 542
You're trying to run it with sh, but bash is actually running it. Try changing #!bin/sh to #!bin/bash and see what happens.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
cannot execute binary file tamilselvan.forum Linux - Newbie 12 10-14-2009 07:15 PM
Cannot execute binary file Nishant Desai Programming 18 10-27-2008 02:37 PM
Can't execute a binary file inverted.gravity Linux - General 4 08-07-2006 10:08 PM
Cannot execute binary file pbagda Linux - General 4 01-19-2004 01:13 AM
Cannot execute binary file Bigun Linux - Software 17 11-03-2002 06:12 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:30 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration