Roel
Posts: 7
Joined: Sun Oct 07, 2012 12:38 pm

(SOLVED) bin/bash not found when trying to run a script

Mon Jan 13, 2014 9:01 am

All, I haven't found a topic regarding this, so:

To keep my wifi-connection alive, I found a few scripts, one of them being from this forum (by MrEngman, if I remembre correctly).
However, when I try to run the script, the first message looks like "/bin/bash not found", and then signals like "unexpected done, expecting fi" etc.

So it seems like something IS done, but not completely or sufficiently. Should something be done in order to run scripts properly?
Last edited by Roel on Tue Jan 14, 2014 8:51 pm, edited 1 time in total.

texy
Forum Moderator
Forum Moderator
Posts: 5155
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: bin/bash not found when trying to run a script

Mon Jan 13, 2014 12:37 pm

Hi and welcome to the forum.
Sorry - you need to give us more info - which script are you taking about? Which wifi dongle?
If you have the Edimax type then this may be useful :
http://www.raspberrypi.org/forum/viewto ... 0b#p483763

Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

User avatar
RaTTuS
Posts: 10373
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK

Re: bin/bash not found when trying to run a script

Mon Jan 13, 2014 12:49 pm

can you post the script here [using code blocks]
have you downloaded the script using windows?
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

Roel
Posts: 7
Joined: Sun Oct 07, 2012 12:38 pm

Re: bin/bash not found when trying to run a script

Mon Jan 13, 2014 1:33 pm

Yes, I used this one:

Code: Select all

#!/bin/bash

while true ; do
   if ifconfig wlan0 | grep -q "inet addr:" ; then
      sleep 60
   else
      echo "Network connection down! Attempting reconnection."
      ifup --force wlan0
      sleep 10
   fi
done
And it came from http://www.raspberrypi.org/phpBB3/viewtopic.php?t=16054

Thanks!

*edit* No I completely retyped it from my Debian machine using vim. So no Windows involved here.

I am (besides the wifi-keep-alive routine) just curious why my RPi just doesn't "eat" script.

User avatar
RaTTuS
Posts: 10373
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK

Re: bin/bash not found when trying to run a script

Mon Jan 13, 2014 1:42 pm

are you using raspbian or openelec or arch or something else ?
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

Roel
Posts: 7
Joined: Sun Oct 07, 2012 12:38 pm

Re: bin/bash not found when trying to run a script

Mon Jan 13, 2014 2:02 pm

I am using Raspbian, and by the way, the dongle is a white TP-Link with a realtek chipset, which needs firmware-realtek.

By the way, I AM familiar with Debian, I just never used scripts so far.

User avatar
duberry
Posts: 379
Joined: Mon Jan 28, 2013 10:44 pm
Location: standing on a planet that's evolving. And revolving at nine hundred miles an hour

Re: bin/bash not found when trying to run a script

Mon Jan 13, 2014 5:56 pm

what is displayed when you type

Code: Select all

which bash 
in a terminal ?

fyi
i get this
[email protected] / $ which bash
/bin/bash
[email protected] / $
lend me your arms, fast as thunderbolts, for a pillow on my journey.
If the environment was a bank, would it be too big to fail
so long; and thanks for all the pi

User avatar
redhawk
Posts: 3465
Joined: Sun Mar 04, 2012 2:13 pm
Location: ::1

Re: bin/bash not found when trying to run a script

Mon Jan 13, 2014 7:32 pm

If you edit your script with vi (not pico or nano) is each line terminated with ^M ??

Richard S.

Roel
Posts: 7
Joined: Sun Oct 07, 2012 12:38 pm

Re: bin/bash not found when trying to run a script

Tue Jan 14, 2014 5:59 am

duberry:

Code: Select all

[email protected] ~ $ which bash
/bin/bash
[email protected] ~ $
redhawk: no, not a single line was ended with ^M

Should it be?

User avatar
rpdom
Posts: 14703
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: bin/bash not found when trying to run a script

Tue Jan 14, 2014 7:00 am

Perhaps you could try typing in a minimal script to see if that works.

Code: Select all

#!/bin/bash
echo "It works!"
Then chmod 700 myscript, (or whatever you called it) and run with ./myscript

User avatar
Richard-TX
Posts: 1549
Joined: Tue May 28, 2013 3:24 pm
Location: North Texas

Re: bin/bash not found when trying to run a script

Tue Jan 14, 2014 7:49 am

Roel wrote:Yes, I used this one:
I don't like the syntax of that shell script.
Here is how I would write it.

Code: Select all

#!/bin/sh
# I use /bin/sh for scripts.  It keeps things saner....and smaller and maybe more secure.
while true 
do
ifconfig wlan0 | grep  -q "inet addr:" 
if [ $? -eq 0 ]
 then
 sleep 60
# I added the exit 0 since once the connection is up, there is no need for the script to continue running.
# If the above statement is not true then comment out the next line. 
 exit 0
else
     echo "Network connection down! Attempting reconnection."
      ifup --force wlan0
      sleep 10
fi
done
Richard
Doing Unix since 1985.
The 9-25-2013 image of Wheezy can be found at:
http://downloads.raspberrypi.org/raspbian/images/raspbian-2013-09-27/2013-09-25-wheezy-raspbian.zip

Roel
Posts: 7
Joined: Sun Oct 07, 2012 12:38 pm

Re: bin/bash not found when trying to run a script

Tue Jan 14, 2014 10:53 am

rpdom: OK, will do. But I guess I need to (sudo) chmod +x in order to run the script?

Richard-TX: thank you, I'll check this tonight as well. Only thing that raises a question is your "I added the exit 0 since once the connection is up, there is no need for the script to continue running" statement.

The idea is to run a script in the background that checks the connection every x minutes , and bring up the interface again once the connection was lost (which, unfortunately, happens every now and then using wireless).

The other solution would be to work with wicd-curses, but I read a lot of nasty things about connection duration of wicd-curses...

User avatar
rpdom
Posts: 14703
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: bin/bash not found when trying to run a script

Tue Jan 14, 2014 12:46 pm

Roel wrote:rpdom: OK, will do. But I guess I need to (sudo) chmod +x in order to run the script?
As you own the script you don't need sudo. Also chown 700 will set the permissions to -rwx------ which is enough for you to run it (chmod +x sets all three "x" bits)

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

Re: bin/bash not found when trying to run a script

Tue Jan 14, 2014 1:09 pm

Also chown 700 will set the permissions to ...
Actually,

Code: Select all

chown 700 file
will set the ownership of the file to the user who's uid is 700 - which probably doesn't exist on your system.

Note that the above command does have to be run either as root or via sudo, because of stupid restrictions that were placed on the Unix "chown" functionality sometime in the last few decades.
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)

User avatar
Yesfan
Posts: 2
Joined: Mon Oct 15, 2012 2:28 pm

Re: bin/bash not found when trying to run a script

Tue Jan 14, 2014 1:12 pm

rpdom wrote:
Roel wrote:rpdom: OK, will do. But I guess I need to (sudo) chmod +x in order to run the script?
As you own the script you don't need sudo. Also chown 700 will set the permissions to -rwx------ which is enough for you to run it (chmod +x sets all three "x" bits)
rpdom, you meant "chmod 700", right? "chown" changes the owner of the file, not the file permissions.

Pete

User avatar
jojopi
Posts: 3078
Joined: Tue Oct 11, 2011 8:38 pm

Re: bin/bash not found when trying to run a script

Tue Jan 14, 2014 1:28 pm

"chmod +x" sets all the execute bits that are not prohibited by your current umask. That is almost always what you want, otherwise you should change your umask. (On the other hand, "chmod -x" clears the execute bits except any that are set but prohibited by umask. That is not very useful, so you should use "chmod a-x" to clear them all instead.)

We do not seem to be getting any closer to diagnosing the actual problem. The errors in the original post are not reported very accurately, but I cannot produce anything even close to them by the usual faults of CR-LF line endings, or literal no-break spaces in a copy and paste.

If Roel has "completely retyped" the script, then I suspect the version we see above is not the same one being executed.

Roel
Posts: 7
Joined: Sun Oct 07, 2012 12:38 pm

Re: bin/bash not found when trying to run a script

Tue Jan 14, 2014 1:37 pm

jojopi wrote:We do not seem to be getting any closer to diagnosing the actual problem. The errors in the original post are not reported very accurately, but I cannot produce anything even close to them by the usual faults of CR-LF line endings, or literal no-break spaces in a copy and paste.

If Roel has "completely retyped" the script, then I suspect the version we see above is not the same one being executed.
I found the script here: http://www.raspberrypi.org/phpBB3/viewtopic.php?t=16054

And yes, I retyped it because I was vi-ing through ssh. and didn't know how to paste in vi from clipboard...

User avatar
Richard-TX
Posts: 1549
Joined: Tue May 28, 2013 3:24 pm
Location: North Texas

Re: bin/bash not found when trying to run a script

Tue Jan 14, 2014 2:24 pm

Rule of thumb for executables.


chmod 755 filename

Ownership of the file does not matter.

run yours as root. ie sudo /full/pathto/filename
Richard
Doing Unix since 1985.
The 9-25-2013 image of Wheezy can be found at:
http://downloads.raspberrypi.org/raspbian/images/raspbian-2013-09-27/2013-09-25-wheezy-raspbian.zip

User avatar
Richard-TX
Posts: 1549
Joined: Tue May 28, 2013 3:24 pm
Location: North Texas

Re: bin/bash not found when trying to run a script

Tue Jan 14, 2014 2:32 pm

you might check for control characters in the original script.

cat -v filename should work.
Richard
Doing Unix since 1985.
The 9-25-2013 image of Wheezy can be found at:
http://downloads.raspberrypi.org/raspbian/images/raspbian-2013-09-27/2013-09-25-wheezy-raspbian.zip

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

Re: bin/bash not found when trying to run a script

Tue Jan 14, 2014 2:40 pm

Rule of thumb for executables.

chmod 755 filename
N.B. The "chmod" thing is only necessary for scripts. It is important to note that compilers will set the executable bit for you when they create the final output file (Nitpick: I suppose technically you could say that it is the assembler that creates the final output file, and thus sets the executable bit).

In a way, this is kind of an annoying inconvenience for scripts. In a perfect world, it wouldn't be necessary - especially because (when you really think it through), there isn't really a meaningful distinction between "executable" and "readable" in the world of scripts (as there, in fact, is in the world of compiled executables).

Anyway, I have a macro in vi(m) that saves the file and makes it executable; I use this the first time I save any script:

Code: Select all

map <leader>X :w<bar>call system('chmod +x '.bufname(""))<bar>e<cr>
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)

User avatar
rpdom
Posts: 14703
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: bin/bash not found when trying to run a script

Tue Jan 14, 2014 4:44 pm

Yesfan wrote:
rpdom wrote:
Roel wrote:rpdom: OK, will do. But I guess I need to (sudo) chmod +x in order to run the script?
As you own the script you don't need sudo. Also chown 700 will set the permissions to -rwx------ which is enough for you to run it (chmod +x sets all three "x" bits)
rpdom, you meant "chmod 700", right? "chown" changes the owner of the file, not the file permissions.

Pete
Yes, sorry. I was in a hurry to get back to work and didn't check what I typoed. Mea culpa :(

wimble
Posts: 34
Joined: Tue Feb 05, 2013 9:52 am

Re: bin/bash not found when trying to run a script

Tue Jan 14, 2014 5:02 pm

Roel wrote:And yes, I retyped it because I was vi-ing through ssh. and didn't know how to paste in vi from clipboard...
If you're using PuTTY to connect from a Windows machine to the Pi, then it's right click, so you end up with the following sequence:

Code: Select all

vi network-monitor.sh  (to edit the blank file)
i                      (to get into insert mode)
right-click            (to insert the copied text)
Esc                    (to return to command mode)
:wq                    (to write the file and quit)
You can also use shift-Insert instead of the right click instead.

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

Re: bin/bash not found when trying to run a script

Tue Jan 14, 2014 5:22 pm

You can also use shift-Insert instead of the right click instead.
Yes, it is always better to use Shift/Insert instead of messing around with mice and menus.

Also, when I create a file on Unix that comes from the ciipboard, it is usually better to start with:

Code: Select all

cat > file
Shift/Insert
Control/D


Followed by:

Code: Select all

vim file
Because vi(m) is (in my systems) configured (and if it isn't on your systems, it should be) for auto-indent. So, when doing a big paste, it is safer to use cat rather than vi(m).
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)

Roel
Posts: 7
Joined: Sun Oct 07, 2012 12:38 pm

Re: bin/bash not found when trying to run a script

Tue Jan 14, 2014 8:49 pm

You are right, the script showed terrible symbols when viewing with cat -v.

This time I copied and pasted using shift-insert (of which feature I did NOT know) and it works like a charm.

The script is running as it is and I'm curious if it does what it promises.
Later on I will try the other script and to see what happens.

Sorry to have kept you all busy for such stupid mistake of mine...

Thanks all!!

Return to “Troubleshooting”