shaxs
Posts: 8
Joined: Tue May 13, 2014 7:46 pm

/bin/sh : bad interpreter: No such file or directory

Tue May 13, 2014 8:00 pm

I followed the following tutorial http://readwrite.com/2014/04/10/raspber ... b-browsing to create a Rpi vpn server. The main difference is the writer here has the eth01 interface set to dhcp and mine is set to static.

There is a part of the tutorial where you add a firewall rule file to /etc/network/interfaces. Since mine is static, it differs from the tutorial. When I try to add "pre-up /etc/firewall-openvpn-rules.sh" to this file, when I reboot my interface is not given an IP address.

I have tried adding it below "iface eth0 inet static" and also after "gateway 192.168.1.254" but either time the Rpi does not get an IP.

You can see the file contents here: http://pastebin.com/9313CDrm.

I come to find out that when executing the file firewall-openvpn-rules.sh manually, I get the error : "/bin/sh : bad interpreter: No such file or directory " which as I understand having a bad pre-up script will cause the the network interface to not activate.

firewall-openvpn-rules.sh contains the following:

#!/bin/sh iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j SNAT --to-source 192.168.1.100

When I run "which sh" I get "/bin/sh".

Running "ls /bin/sh" just returns "/bin/sh"

I think at this point I need to figure out why I am getting "/bin/sh : bad interpreter: No such file or directory ". Anyone have a clue?

User avatar
DougieLawson
Posts: 42232
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK

Re: /bin/sh : bad interpreter: No such file or directory

Tue May 13, 2014 10:24 pm

firewall-openvpn-rules.sh should look like this

Code: Select all

#!/bin/sh
 iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j SNAT --to-source 192.168.1.100
The #! shebang line needs to be separated from the command you're going to run in the shell.
Languages using left-hand whitespace for syntax are ridiculous

DMs sent on https://twitter.com/DougieLawson or LinkedIn will be answered next month.
Fake doctors - are all on my foes list.

The use of crystal balls and mind reading is prohibited.

User avatar
Paeryn
Posts: 3506
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: /bin/sh : bad interpreter: No such file or directory

Tue May 13, 2014 10:29 pm

Is the contents of firewall-openvpn-rules.sh all on one line? If so that won't work as the #!/bin/sh needs to be on a line on its own, eg

Code: Select all

#!/bin/sh
iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j SNAT --to-source 192.168.1.100
She who travels light — forgot something.
Please note that my name doesn't start with the @ character so can people please stop writing it as if it does!

shaxs
Posts: 8
Joined: Tue May 13, 2014 7:46 pm

Re: /bin/sh : bad interpreter: No such file or directory

Tue May 13, 2014 10:33 pm

Yes sorry it is on different lines.

It looks like this:

#!/bin/sh
iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j SNAT --to-source 192.168.1.100

When I view it using nano, the first line is blue.

User avatar
DougieLawson
Posts: 42232
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK

Re: /bin/sh : bad interpreter: No such file or directory

Tue May 13, 2014 10:37 pm

sudo apt-get install dos2unix
sudo dos2unix firewall-openvpn-rules.sh

That will strip any spurious characters off the ends of every line (you can't see them with nano).
Languages using left-hand whitespace for syntax are ridiculous

DMs sent on https://twitter.com/DougieLawson or LinkedIn will be answered next month.
Fake doctors - are all on my foes list.

The use of crystal balls and mind reading is prohibited.

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: /bin/sh : bad interpreter: No such file or directory

Tue May 13, 2014 10:38 pm

This sort of thing is usually caused by editing the file on a Windows machine.

Our old friend, the DOS/Unix line endings difference.

Did you, by any chance, edit the file on Windows (at any point)? "At any point" is relevant, since many (most?) editors will respect whatever line ending the file has - and preserve it. So, it's sort of like a virus - once it gets there, it stays.
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

shaxs
Posts: 8
Joined: Tue May 13, 2014 7:46 pm

Re: /bin/sh : bad interpreter: No such file or directory

Tue May 13, 2014 11:37 pm

Joe Schmoe wrote:This sort of thing is usually caused by editing the file on a Windows machine.

Our old friend, the DOS/Unix line endings difference.

Did you, by any chance, edit the file on Windows (at any point)? "At any point" is relevant, since many (most?) editors will respect whatever line ending the file has - and preserve it. So, it's sort of like a virus - once it gets there, it stays.
Nope. All done on the Rpi. Though I did copy and paste the contents.

But I did run it through VI and change the file type to Unix JUST in case.

shaxs
Posts: 8
Joined: Tue May 13, 2014 7:46 pm

Re: /bin/sh : bad interpreter: No such file or directory

Tue May 13, 2014 11:40 pm

And here is what I get when I run the file manually:

root@raspberrypi:/etc# ./firewall-openvpn-rules.sh
bash: ./firewall-openvpn-rules.sh: /bin/sh : bad interpreter: No such file or directory
root@raspberrypi:/etc#

Tarcas
Posts: 741
Joined: Thu Jan 09, 2014 5:38 am
Location: USA

Re: /bin/sh : bad interpreter: No such file or directory

Wed May 14, 2014 12:09 am

shaxs wrote:And here is what I get when I run the file manually:

root@raspberrypi:/etc# ./firewall-openvpn-rules.sh
bash: ./firewall-openvpn-rules.sh: /bin/sh : bad interpreter: No such file or directory
root@raspberrypi:/etc#
Sounds like it's calling the file correctly... does the /bin/sh shell exist on your system? (It would be unusual if it didn't, and might indicate a corrupt SD card.) If it's missing, you could just change it to #!/bin/bash or whatever other shell you use. If it's there... someone more experienced than I will have to offer suggestions, because your error says it's not.

User avatar
Paeryn
Posts: 3506
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: /bin/sh : bad interpreter: No such file or directory

Wed May 14, 2014 12:46 am

Try creating the file from scratch on the rpi without copy-pasting, it looks like there's a rouge control character that has copied over at the end of the line.
The "Bad Interpreter" error means that it can't find the command given after the #!, and in the error message seems to be showing a space between /bin/sh and the : where there shouldn't be one.

Code: Select all

bash: ./firewall-openvpn-rules.sh: /bin/sh : bad interpreter: No such file or directory
                                          ^ Here, this space suggests that there is an extra (invisible?) character at the end of the line.
What's the output of

Code: Select all

hexdump -C firewall-openvpn-rules.sh
The first line should be

Code: Select all

pi@raspberrypi ~ $ hexdump -C firewall-openvpn-rules.sh
00000000  23 21 2f 62 69 6e 2f 73  68 0a 69 70 74 61 62 6c  |#!/bin/sh.iptabl|
Note: there shouldn't be any other pair between the 68 and 0a (the h and the end-of-line) - unless it is just a space (68 20 0a), that's allowed.
She who travels light — forgot something.
Please note that my name doesn't start with the @ character so can people please stop writing it as if it does!

shaxs
Posts: 8
Joined: Tue May 13, 2014 7:46 pm

Re: /bin/sh : bad interpreter: No such file or directory

Wed May 14, 2014 4:09 am

Code: Select all

root@raspberrypi:/etc# hexdump -C firewall-openvpn-rules.sh
00000000  23 21 2f 62 69 6e 2f 73  68 c2 a0 0a 69 70 74 61  |#!/bin/sh...ipta|
00000010  62 6c 65 73 20 2d 74 20  6e 61 74 20 2d 41 20 50  |bles -t nat -A P|
00000020  4f 53 54 52 4f 55 54 49  4e 47 20 2d 73 20 31 30  |OSTROUTING -s 10|
00000030  2e 38 2e 30 2e 30 2f 32  34 20 2d 6f 20 65 74 68  |.8.0.0/24 -o eth|
00000040  30 20 2d 6a 20 53 4e 41  54 20 2d 2d 74 6f 2d 73  |0 -j SNAT --to-s|
00000050  6f 75 72 63 65 20 31 39  32 2e 31 36 38 2e 31 2e  |ource 192.168.1.|
00000060  31 30 30 0a 0a                                    |100..|
00000065
So looks like there is an issue. Im going to try typing the file out from scratch.

shaxs
Posts: 8
Joined: Tue May 13, 2014 7:46 pm

Re: /bin/sh : bad interpreter: No such file or directory

Wed May 14, 2014 4:19 am

AHA! I redid the file from scratch and it fixed it! Thank you for your help. Now let me see if I can get this vpn to work :)

shaxs
Posts: 8
Joined: Tue May 13, 2014 7:46 pm

Re: /bin/sh : bad interpreter: No such file or directory

Wed May 14, 2014 6:44 am

AAANNNDDD the RPi VPN is working!!!! There were like 5 errors in the tutorial I had to work through. Pretty bad errors. But it works like a champ on my Android phone.

User avatar
Paeryn
Posts: 3506
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: /bin/sh : bad interpreter: No such file or directory

Wed May 14, 2014 12:36 pm

Glad it's sorted. I just checked the tutorial page you were following, the bit you copy-pasted had a non-breaking space at the end of the first line. That's the problem with trying to copy-paste from web sites, what you see isn't always what you get.
She who travels light — forgot something.
Please note that my name doesn't start with the @ character so can people please stop writing it as if it does!

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: /bin/sh : bad interpreter: No such file or directory

Wed May 14, 2014 2:51 pm

Paeryn wrote:Glad it's sorted. I just checked the tutorial page you were following, the bit you copy-pasted had a non-breaking space at the end of the first line. That's the problem with trying to copy-paste from web sites, what you see isn't always what you get.
That makes sense, because a "non-breaking space" is (AFAIK) represented by ascii code 160 (A0 hex) and that was the character in the file as displayed by "od".
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

shaxs
Posts: 8
Joined: Tue May 13, 2014 7:46 pm

Re: /bin/sh : bad interpreter: No such file or directory

Wed May 14, 2014 3:26 pm

Thanks again! The Rpi vpn works for internal addresses like 192.168.1.xxx. But when connected to the VPN I cannot access sites like google.com.

Any idea with OpenVPN would not be accessible to external network sites?

flafla
Posts: 4
Joined: Sat May 17, 2014 7:45 pm

Re: /bin/sh : bad interpreter: No such file or directory

Sat May 17, 2014 7:51 pm

@shaxs:
Hi,
I have exactly the same problem. I use a VPN provider and i'm using openVPN to connect to it with the RaspberryPi.
One the VPN is connected, I can't go anymore on the internet.

Just in case, i've watched several tutorials:
http://www.naspberrypi.com/openvpn.html/
the one in the first post that you used/
and http://ubuntuforums.org/showthread.php?t=1660520
Without any succes.

Also, i'm new to Rpi and raspbian ;)

Bye, thanks for this topic !

ps. found this topic in french, which seems to work for some Rpi users https://tech.kanka.ch/index.php/faire-t ... ur-debian/

flafla
Posts: 4
Joined: Sat May 17, 2014 7:45 pm

Re: /bin/sh : bad interpreter: No such file or directory

Sun May 18, 2014 10:30 am

Hi again,
I've also tried (really quickly) the shorewall solution with no succes , which is a iptables manager.
IT's probably a valuable solution if you can watch, I also saw on the website the possibility to add the VPN (tun0 device for me)

(some hints here, for version 3.0 (the is a more recent one) http://www.shorewall.net/3.0/VPNBasics.html)
bye

Return to “Raspberry Pi OS”