I cannot quite explain how my log ended up like this but it must have something to do with my Windows machine.
I mean - look at the carriage return symbols. I think I have spoiled the script with an accidental CR character. Possibly the 2 parts of the log are concatenated from 2 different runs and one of them is a broken script.
I copied and pasted from Notepad++ into a nano window in PuTTY.
I don't see a CR in Notepad++ but this error in the log is typical when there's a carriage return in a shell script.
Must be Windows' copy-paste problem and it's in the bottom.
Disregard the log I attached initially, it's probably flawed and I couldn't reproduce it in 10 attempts.
The script simply stops at get nvram with no error message.
I checked one more thing: what if I completely removed any attached USB media and rebooted.
The loop stopped "reliably" between 2000 and 4000 every single time, 5 out of 5 tries.
I checked one more thing: what if I completely removed any attached USB media and rebooted.
The loop stopped "reliably" between 2000 and 4000 every single time, 5 out of 5 tries.
I took this into consideration and I revised my one above to have a while loop with defined limits. @Viktor Jaep try my new revised one from the previous post. With the new suggestions..
I took this into consideration and I revised my one above to have a while loop with defined limits. @Viktor Jaep try my new revised one from the previous post. With the new suggestions..
I took this into consideration and I revised my one above to have a while loop with defined limits. @Viktor Jaep try my new revised one from the previous post. With the new suggestions..
That's why I asked how to use milliseconds.
I wanted to give the CPU time to breathe but 1 sec pauses made the script too slow.
The result was that pauses didn't seem to improve reliability. Loop still hanged up at around the same number of iterations.
Tried with sleep of about 0.05 to 0.2 sec.
For me, this is not completely random. Very often the loop stops between 2500 and 3200 iterations.
Doesn't matter how much time I give between the iterations.
Is there any cache involved in reading the nvram? Anything that can run out? Anything we could flush?
#!/bin/sh
trap '' HUP INT QUIT ABRT TERM
(i="0"
while true; do
i="$(( i + 1 ))"
for nv in 1 2 3 4 5; do
unset "state${nv}";
eval "state${nv}"="$(/bin/nvram get vpn_client${nv}_state)";
done
clear
echo "$state1" "$state2" "$state3" "$state4" "$state5"
echo "$i"
done) > /tmp/mynvramerror.log 2>&1 &
exit 0
Edit: I revised it by removing the sleep 1.
After executing I ran tail -f /tmp/mynvramerror.log.
Heres a little more info about eval.
The eval command is used to execute the arguments as a shell command on unix or linux system. Eval command comes in handy when you have a unix or linux command stored in a variable and you want to execute that command stored in the string.