LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-25-2004, 11:08 AM   #1
grueugene
LQ Newbie
 
Registered: Mar 2004
Posts: 6

Rep: Reputation: 0
Cannot execute a script


Hi, all.

I have a script and when trying to exeute it I get an error:

: bad interpreter: No such file or directory

The thing is it executes at one server, but does not at another.

NEED YOUR HELP!!!

Thank's

Eugene
 
Old 03-25-2004, 11:18 AM   #2
Looking_Lost
Senior Member
 
Registered: Apr 2003
Location: Eire
Distribution: Slackware 12.0, OpenSuse 10.3
Posts: 1,120

Rep: Reputation: 45
Check the shebang at the start of the script

i.e

#!/bin/bash

or whatver it maybe

probably the one that it won't run on doesn't have the appropriate/linked to the proper shell program.
 
Old 03-25-2004, 11:25 AM   #3
brainstormingin
LQ Newbie
 
Registered: Mar 2004
Location: india
Distribution: red hat 7.3
Posts: 6

Rep: Reputation: 0
it would be good if we could know what kind of script u are trying to run . perl, shell python, javascript ?
 
Old 03-25-2004, 12:03 PM   #4
daveyboy685
LQ Newbie
 
Registered: Mar 2004
Posts: 4

Rep: Reputation: 0
You might have to execute like this:

./shell.sh
 
Old 03-25-2004, 12:09 PM   #5
grueugene
LQ Newbie
 
Registered: Mar 2004
Posts: 6

Original Poster
Rep: Reputation: 0
Cannot Execute Script

I'm trying to write bash script: that looks like that

--------------------------------------------------------------------------------------------

#!/bin/bash
# script to calculate monthly occupancy rate for the previoues month

DEBUG=0
debug() {
[ $DEBUG -gt 0 ] && echo $1
}

# global defs
DAYS=$1 && debug "DAYS=$DAYS"
SQLPRG="mysql -u root --password=xxx MyDB" && debug "SQLPRG=$SQLPRG"

# determine location id
SQLCMD="SELECT param_value FROM kc_sys_params WHERE param_category = 'LOCATION' AND param_name = 'LOCATION_ID';"
LOCID=`echo $SQLCMD | $SQLPRG | tail -n 1` && debug "LOCID=$LOCID"

LOCNAME=`hostname | awk -F "." '{print $2}'` && debug "LOCNAME=$LOCNAME"

# determine number of rooms at property
SQLCMD="SELECT COUNT(*) FROM kc_client_parameter WHERE room_nbr < 9999;"
ROOMCOUNT=`echo $SQLCMD | $SQLPRG | tail -n 1` && debug "ROOMCOUNT=$ROOMCOUNT"

# determine total room nights occupied
SQLCMD="SELECT SUM(occupancy) FROM kc_occupancy_rate WHERE timestamp BETWEEN DATE_ADD(CURRENT_DATE, INTERVAL -1 MONTH) AND CURRENT_DATE;"

OCCNIGHTS=`echo $SQLCMD | $SQLPRG | tail -n 1` && debug "OCCNIGHTS=$OCCNIGHTS"

# total available room nights
#1 get number of days in the previous month
SQLCMD="SELECT DAYOFMONTH(DATE_ADD(CURRENT_DATE, INTERVAL -1 DAY));"
DAYS=`echo $SQLCMD| $SQLPRG | tail -n 1` && debug "DAYS=$DAYS"

#2 count total available room nights
ROOMNIGHTS=`expr $ROOMCOUNT "*" $DAYS` && debug "ROOMNIGHTS=$ROOMNIGHTS"

# occupancy rate
#BCCMD="scale=2; $OCCNIGHTS / $ROOMNIGHTS" && debug "BCCMD=$BCCMD"

OCCRATE=`echo $OCCNIGHTS $ROOMNIGHTS | awk '{printf( "%7.2f\n", $1/$2)}'` && debug "OCCRATE=$OCCRATE"

echo "last $DAYS days occupancy for $LOCNAME was $OCCRATE"

----------------------------------------------------------------------------------------

And it executes on one server and gives me an error on another.

I write : ./the_script.sh

And I have an error:

: bad interpreter: No such file or directory

What can it be?

Eugene
 
Old 03-25-2004, 01:06 PM   #6
aluser
Member
 
Registered: Mar 2004
Location: Massachusetts
Distribution: Debian
Posts: 557

Rep: Reputation: 43
bash is either not installed or is installed in a different location than /bin/bash. e.g. on *bsd it may install to /usr/local/bin/bash, or not be installed at all.
 
Old 03-25-2004, 01:27 PM   #7
daveyboy685
LQ Newbie
 
Registered: Mar 2004
Posts: 4

Rep: Reputation: 0
Do the following:

env | grep SHELL and let us know what shell you are running.
How did you create the shell...ie. on pc and then ftp or vi on linux...

If you do a vi <shell name> do you see it open in dos mode...you can see this at the bottom of the screen...
It will look something like this....
"Makefile" [dos] 773L, 35163C
 
Old 03-25-2004, 01:32 PM   #8
aluser
Member
 
Registered: Mar 2004
Location: Massachusetts
Distribution: Debian
Posts: 557

Rep: Reputation: 43
I can recreate the problem right here:
Code:
14:30 aluser@alf:~/test$ cat interp
#!/bin/foo
14:31 aluser@alf:~/test$ ./interp
bash: ./interp: /bin/foo: bad interpreter: No such file or directory
I guarantee it's no more complicated than that
 
Old 03-25-2004, 01:58 PM   #9
grueugene
LQ Newbie
 
Registered: Mar 2004
Posts: 6

Original Poster
Rep: Reputation: 0
Cannot execute script

After executing env | grep SHELL
I get SHELL=/bin/bash

when open vi /bin/bash
I have "/bin/bash" [noeol]

So, looks like everything is fine.

Eugene
 
Old 03-25-2004, 04:44 PM   #10
Looking_Lost
Senior Member
 
Registered: Apr 2003
Location: Eire
Distribution: Slackware 12.0, OpenSuse 10.3
Posts: 1,120

Rep: Reputation: 45
Compare the output of vi /bin/bash to vi /bin/bash on the machine it works on
 
Old 01-26-2005, 03:35 PM   #11
perlMonkey
LQ Newbie
 
Registered: Jan 2005
Posts: 6

Rep: Reputation: 0
Angry A silly variant of this problem

I just re-installed Suse linux 8.0 on my box and I am getting the bad interpreter message no matter what scripting language I use and it doesn't matter where I put the script.
#!/usr/bin/perl
#!/bin/bash
etc...
I checked my /etc/fstab file and everything is pretty much set to 'Defaults', which I believe is rw,exec, blah blah. I don't think that the problem resides there. Is there some configuration script that I need to run in order to associate each interpreter with the file type? The shell should read the first line and figure out what interpreter to use right? I have to manually type in 'perl example.pl' in order for it to run. I changed the permission of scripts to chmod 777 and still no luck. Any ideas here???
 
Old 01-26-2005, 03:49 PM   #12
leadazide
Member
 
Registered: Apr 2004
Location: Germany
Distribution: SuSE 11.0, Ubuntu 7.10
Posts: 390

Rep: Reputation: 30
are you sure you have set the permissions correctly?
try chmod +x shell.sh, then run the script again
and make sure you run it from a linux partition.
 
Old 01-26-2005, 03:57 PM   #13
tmarikle
LQ Newbie
 
Registered: Dec 2004
Posts: 9

Rep: Reputation: 0
Here's a subtle cause for the same problem; doesn't necessarily sound like your situation though.

I move a massive ksh shell script between work and home. By the time I get the file to my Linux system (via Outlook mail, my PC, etc). I end up with DOS carriage returns embedded within the script. VIM hasn't revealed these with ^Ms so I sometimes don't immediate realize what has occurred.

This can be confirmed by using "od"

Code:
od -x | more
If there are 0x0a 0x0d pairs then this will cause the command interpreter to choke with "bad interpreter."

Solution: make sure that you aren't doing a binary transfer of a DOS file. On the target system you can strip them out using many techniques; here's one example:

Code:
tr -d '\015' < script.sh > script.sh.new
mv script.sh.new script.sh
Thomas

Last edited by tmarikle; 01-26-2005 at 03:58 PM.
 
Old 01-26-2005, 04:04 PM   #14
perlMonkey
LQ Newbie
 
Registered: Jan 2005
Posts: 6

Rep: Reputation: 0
I changed permissions on my scripts to 'wide open' rwxrwxrwx and I wrote the scripts using kwrite, so it shouldn't have put those weird carriage return chars on the end. I also use nedit, an editor written in motif that will show the <CR> characters and these scripts just don't have it. I have a couple of unix admins here at work scratching their heads too. I'm stumped.
 
Old 01-27-2005, 04:15 AM   #15
LasseW
Member
 
Registered: Oct 2004
Distribution: Fedora 7, OpenSuse 10.2
Posts: 108

Rep: Reputation: 15
What happens if you remove the shebang line and then try to run the script ?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
execute a script upon logon Starch Linux - Newbie 3 05-12-2005 04:04 PM
Execute script as user sbassett Fedora 1 04-06-2005 10:30 AM
execute a script as a different user JordanH Linux - Software 3 02-08-2005 02:47 PM
Execute Script from Website cartoonwally Linux - General 10 05-28-2004 06:39 PM
Why cant i execute a perl script dude4you Linux - Newbie 2 03-02-2004 05:50 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:13 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