Can you riddle me whats wrong with this?
check () {
if [ "$TEMP" == "v3.3:" ] || [ "$TEMP" == "" ]; then
TEMP="firmware"
sleep 5
fi
}
Its not matching the v3.3: for some reason...
Can you riddle me whats wrong with this?
How are you invoking it? Seems to work ok on my machine:
Can you riddle me whats wrong with this?
How are you invoking it? Seems to work ok on my machine:
#!/bin/bash
read () {
TEMP="$(./temp | cut -d ' ' -f10)"
TIME="$(date +%R)"
}
check () {
if [ "$TEMP" == "v3.3:" ] || [ "$TEMP" == "" ]; then
TEMP="firmware"
sleep 5
fi
}
TEMP="firmware"
until [ $TEMP != "firmware" ]; do
read
echo $TIME $TEMP
check
done
echo $TEMP $TIME
echo "Frankston $TEMP at $TIME" > /bbs/ansi/local.tmp
read () { TEMP="$(./temp | cut -d ' ' -f10)"
Ah, I see the issue. Let's break this apart.
A metapoint: the shell has a builtin command called `read` to read a
check () { if [ "$TEMP" == "v3.3:" ] || [ "$TEMP" == "" ]; then TEMP="firmware"
Note here that you _assign_ $TEMP to the string "firmware" if your conditions match. So if `$TEMP` was "v3.3:" it becomes "firmware".
TEMP="firmware" until [ $TEMP != "firmware" ]; do
This loop will not terminate while "$TEMP" == "firmware".
Metanote: You're running an `until` loop on a negative equality
while [ $TEMP == "firmware" ]; do
check
...But here, you reassign $TEMP to "firmware", overwriting
whatever $TEMP had been.
So when you go around the loop again, $TEMP is "firmware"
and the loop never terminates.
echo "Frankston $TEMP at $TIME" > /bbs/ansi/local.tmp
And these two lines are never executed. Note that the last
line would truncate whatever had been in local.tmp, which
may or may not be what you want.
read () { TEMP="$(./temp | cut -d ' ' -f10)"
the script ./temp queries the thermometer and returns a string full of garbage aside from the temp. Failures show up as "firmware", "", or "v3.3:"
Note here that you _assign_ $TEMP to the string "firmware" if your conditions match. So if `$TEMP` was "v3.3:" it becomes "firmware".
Whats happening here is... firmware, v3.3: and "" are all failures, but I'm looping on firmware, so if it equals one of the other two, I change
it "firmware" A successful result looks like 21.5c. This logic mostly works, at least it does for "" and firmware, I don't comprende why v3.3: is an exception.
As noted above, its only checking one status on the loop, so other failures need to be made into a logical failure. It does terminate
quite nicely in normal use. To be honest, when I started this, firmware was the only issue I was looking for, then I discovered the possible results.
Thats partially right, there are 3 failures, but success is something
that doesn't match any known failure, so while it can look endless, it does exit on anything other than those values.
So long as the values mentioned above aren't met this does get executed, the file local.tmp is only the current time, temperature so overwriting
is a good thing. Its not a log as such. I have that being done
elsewhere.
I might have to cut it out, and pore over it a bit more in a shell, but I'm not entirely with your rewrite.. :/
Maybe I ought to borrow BP's hand and smack my forehead with it a few
Sysop: | sneaky |
---|---|
Location: | Ashburton,NZ |
Users: | 31 |
Nodes: | 8 (0 / 8) |
Uptime: | 232:23:20 |
Calls: | 2,088 |
Calls today: | 2 |
Files: | 11,140 |
Messages: | 948,586 |