User avatar
silverfox0786
Posts: 215
Joined: Mon Feb 04, 2013 10:32 pm
Location: Slough, UK
Contact: Website

bash commands

Sat Feb 09, 2013 2:09 am

hi im using Rasperian Wheezy

i cant seem to deploy commands

i always get a bash error

even to teh point i cant run sh scripts

what is my error

dows any one know please


thanks

User avatar
tonyhughes
Posts: 951
Joined: Wed Dec 26, 2012 3:46 am

Re: bash commands

Sat Feb 09, 2013 3:07 am

Probably your spelling I'd say. The command line is totally unforgiving with spelling mistakes.

Copy and paste one of your commands, and the output it produces, and we will try and help, but until then, your question is not specific enough to be able to help you.

User avatar
pluggy
Posts: 3635
Joined: Thu May 31, 2012 3:52 pm
Location: Barnoldswick, Lancashire,UK
Contact: Website

Re: bash commands

Sat Feb 09, 2013 1:06 pm

if you're running shell commands in the current directory you need to append ,/ to the front of the command.

eg

Code: Select all

./runme
If its something you've downloaded it probably won't have execute permissions and so won't run.

you can fix this by

Code: Select all

chmod +x runme
If the script needs to change files that aren't in the users home folder you probaly will need to put sudo on the front.
Don't judge Linux by the Pi.......
I must not tread on too many sacred cows......

User avatar
silverfox0786
Posts: 215
Joined: Mon Feb 04, 2013 10:32 pm
Location: Slough, UK
Contact: Website

Re: bash commands

Sat Feb 09, 2013 1:27 pm

i know the scripts are good as i wrote them a few years ago and they work flawlessly in Linux Ubuntu x86 architechure

since apt-get upgrade etc commands are working which is weird but still no sh commands

i have also noticed my crontabs have stopped working

here is a common command i deployed and output i got

Code: Select all

login as: pi
[email protected]'s password:
Linux raspberrypi 3.2.27+ #250 PREEMPT Thu Oct 18 19:03:02 BST 2012 armv6l

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Sat Feb  9 13:28:39 2013 from 192.168.1.4
[email protected] ~ $ cd /tmp
[email protected] /tmp $ chmod +x OscamCheck.sh
[email protected] /tmp $ ./OscamCheck.sh
-bash: ./OscamCheck.sh: /bin/bash^M: bad interpreter: No such file or directory
[email protected] /tmp $

Code: Select all

[email protected] /tmp $ ls
OscamCheck.sh  pulse-osd0kVkucg0p  pulse-PKdhtXMmr18n

User avatar
rurwin
Forum Moderator
Forum Moderator
Posts: 4258
Joined: Mon Jan 09, 2012 3:16 pm
Contact: Website

Re: bash commands

Sat Feb 09, 2013 1:37 pm

Your script file has an invalid #! line at the beginning. It should probably be:

Code: Select all

#! /bin/bash

User avatar
pluggy
Posts: 3635
Joined: Thu May 31, 2012 3:52 pm
Location: Barnoldswick, Lancashire,UK
Contact: Website

Re: bash commands

Sat Feb 09, 2013 1:44 pm

It looks to me like the shell script is trying to access a program or file that isn't there. We'd need to know the contents of OscamCheck.sh .

like

Code: Select all

cat OscamCheck.sh 
Don't judge Linux by the Pi.......
I must not tread on too many sacred cows......

DBryant
Posts: 281
Joined: Sat Feb 02, 2013 12:41 pm
Location: Berkshire, UK

Re: bash commands

Sat Feb 09, 2013 1:49 pm

What is your PATH set to?

Run
echo $PATH

and you'd expect to see something like
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games:/opt/vc/bin

If this doesn't include /bin for example, where bash is usually installed, then this is a source of your problems. Try 'ls /bin' first and then 'ls /bin/bash', both should return something. (In my professional life I've found this it to be deleted to make space, on the basis it's a bin-directory (as in trash) , as opposed to bin(ary)!)

If you run:
which bash

it should report the fully resolved name for bash which (/bin/bash usually). It will be selecting the first bash found in the PATH list, so if that's empty for example, then problem.

Obviously this should be what's at the top of your script in the hash-bang line.

User avatar
silverfox0786
Posts: 215
Joined: Mon Feb 04, 2013 10:32 pm
Location: Slough, UK
Contact: Website

Re: bash commands

Sat Feb 09, 2013 1:52 pm

here is the script

Code: Select all

#!/bin/bash
TARGETDIR=/media/card/camlogs/oscam
FILE=oscam.check
process=$(ps auxwww | grep oscam | grep -v grep | awk 'NR==1 {print $2}' | sed 's/\n//g')
if [ -z $process ]; then
echo "$(date): Couldn't find oscam running. Restarting server-binary" >> $TARGETDIR/$FILE
/usr/local/bin/oscam -b -c /var/etc/config
else
echo "$(date): Oscam is running, now checking if it is responding like it should" >> $TARGETDIR/$FILE
port=$(cat /var/etc/configs/oscam.conf | grep httpport | awk 'NR==1 {print $3}')
frozen=$(nc 127.0.0.1 16002 | grep Forbidden | awk 'NR==1 {print $3}')
if [ $frozen="Forbidden" ]; then
echo "$(date): Oscam is responding like it should" >> $TARGETDIR/$FILE
else
echo "$(date): Oscam is frozen, Restarting..." >> $TARGETDIR/$FILE
echo "$(date): Stopping Oscam" >> $TARGETDIR/$FILE
OScamPID=$(pidof oscam)
kill -9 $OScamPID
sleep 1
echo "$(date): Starting Oscam" >> $TARGETDIR/$FILE
/usr/local/bin/oscam -b -c /var/etc/config
fi
fi

User avatar
silverfox0786
Posts: 215
Joined: Mon Feb 04, 2013 10:32 pm
Location: Slough, UK
Contact: Website

Re: bash commands

Sat Feb 09, 2013 1:58 pm

DBryant wrote:What is your PATH set to?

Run
echo $PATH

and you'd expect to see something like
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games:/opt/vc/bin

If this doesn't include /bin for example, where bash is usually installed, then this is a source of your problems. Try 'ls /bin' first and then 'ls /bin/bash', both should return something. (In my professional life I've found this it to be deleted to make space, on the basis it's a bin-directory (as in trash) , as opposed to bin(ary)!)

If you run:
which bash

it should report the fully resolved name for bash which (/bin/bash usually). It will be selecting the first bash found in the PATH list, so if that's empty for example, then problem.

Obviously this should be what's at the top of your script in the hash-bang line.

this is what i have

Code: Select all

[email protected] /tmp $ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/u                      sr/games

Code: Select all

[email protected] /tmp $ which bash
/bin/bash

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

Re: bash commands

Sat Feb 09, 2013 2:09 pm

Code: Select all

[email protected] /tmp $ ./OscamCheck.sh
-bash: ./OscamCheck.sh: /bin/bash^M: bad interpreter: No such file or directory
There's your problem: your file is using DOS style line endings (carriage return, linefeed), rather than Unix style (linefeed). So the carriage return is being picked up as part of the interpreter name, and it's trying to run "/bin/bash^M", not "/bin/bash"

You should be able to fix it with:

Code: Select all

tr -d "\015" < OscamCheck.sh > OscamCheck2.sh

User avatar
silverfox0786
Posts: 215
Joined: Mon Feb 04, 2013 10:32 pm
Location: Slough, UK
Contact: Website

Re: bash commands

Sat Feb 09, 2013 2:11 pm

Grrrrrrrrrrrrrr


i reinstalled windows and edited the sh file since

i forgot to tell notepad ++ in setting to use Unix line ending


LOL thanks will try that now

User avatar
silverfox0786
Posts: 215
Joined: Mon Feb 04, 2013 10:32 pm
Location: Slough, UK
Contact: Website

Re: bash commands

Sat Feb 09, 2013 2:20 pm

beautiful :)


I love the RPi Community

All working now

just have to fix the rest of the scripts


thanks guys

now to work out why cron not running even though its started

Code: Select all

[email protected] ~ $ service cron status
[ ok ] cron is running.

jamiesk
Posts: 95
Joined: Mon Nov 26, 2012 8:48 pm
Location: Ipswich, Suffolk, England, UK.

Re: bash commands

Sun Feb 10, 2013 1:22 am

Cron is the daemon which runs, you tell it via the table crontab when to run your command/scripts.

crontab -l
And
crontab -e
Are your frinds here 8-)
Pi1 (Nov 2012 loft)= 1KW immersion controller for Solar panel
Pi2 (Jan 2013 living room)=Play thing
Pi3 (Feb 2013 mobile)= Play thing with Tandy Ladder board,breakout board,Nokia display
http://www.raspberrypi.org/phpBB3/viewtopic.php?f=26&t=28193

User avatar
socialdefect
Posts: 110
Joined: Mon Jun 25, 2012 9:02 pm
Location: Tilburg, the Netherlands
Contact: Website

Re: bash commands

Mon Feb 11, 2013 9:36 pm

If I'm not mistaking you can change the line-endings of your scripts with every Linux texteditor. I believe all there's to it is deleting a space at the end of the first line that probably reads: #!/bin/bash_
== If it's not broke... I'm not done fixing it! ==

Return to “Beginners”