0
#!/bin/bash 
while :
do
    echo twerkin
    exec free -h > /ver/www/raspberry/load.txt
    exec /opt/vc/bin/vcgencmd measure_temp > /var/www/raspberry/heat.txt
done

This is what I made, I am going to read it on my website, but thats not the problem. The problem is that it gives me this error:

pi@raspberrypi ~ $ sh showinfo.sh
showinfo.sh: 7: showinfo.sh: Syntax error: "done" unexpected (expecting "do")

I'm running this on my raspberry pi with Raspbian (Debian Wheezy)

4
  • 1
    Please add the error to the question Commented Oct 22, 2014 at 10:26
  • Added error, (it was in the image previously) Commented Oct 22, 2014 at 10:31
  • 1
    Running a Bash script with sh is always an error. But your script works fine here (apart from the obvious misunderstanding of what exec does) without errors. Commented Oct 22, 2014 at 10:32
  • Why is it not working over here than? Is it because of the stripped out version of Debian Wheezy??? (Raspbian) Commented Oct 22, 2014 at 10:34

2 Answers 2

2

You don't seem to understand what the exec keyword does. It replaces your current script (basically, thewhile loop) with the free command.

To run a command, simply specify it.

#!/bin/bash

while : ; do
    free -h
    /opt/vc/bin/vcgencmd measure_temp 
done

(I omitted the redirections because you were overwriting the old results on each iteration. What do you actually want?)

Sign up to request clarification or add additional context in comments.

3 Comments

How can I let bash run another program than?
I want output from every thing I run in 2 seperate files, so free- h in /var/www/raspberry/load.txt and the output from /opt/vc/bin/vcgencmd measure_temp in /var/www/raspberry/heat.txt, so that I can read them with HTML.
They are not HTML. If you want to append to the file on each iteration, use >>.
0

try to change few things in your script

#!/bin/bash 

while : ;
do
    echo twerkin

    #### commands to execute are not need to be prefixed with exec
    #### + concatenate output with >>
    free -h >> /ver/www/raspberry/load.txt

    #### same here
    /opt/vc/bin/vcgencmd measure_temp >> /var/www/raspberry/heat.txt

    #### you probably would want to add a delay here, because in other way
    #### the script will be executed probably way too fast
    # sleep 0.01

done

2 Comments

Thanks for you input! But it gives this error: pi@raspberry ~ $ ./showinfo.sh : no such file or directory
I found another way to do it without the loop, I don't know why it doesn't work. Has it anything to do with SSH?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.