While Loop
Posted: Thu Feb 19, 2015 7:05 pm
Hi i have a bash script with a 1 second while loop running at every boot. I want to know will a while loop script slow down the raspberry pi?
A small, affordable computer with free resources to help people learn, make things, and have fun
https://www.raspberrypi.org/forums/
https://www.raspberrypi.org/forums/viewtopic.php?f=91&t=100930
I run this script @reboot using crontab.rpdom wrote:If you mean you have a loop with a "sleep 1" in it, that won't load the Pi at all.
If you have a loop where it is constantly checking the time to see if a second has passed, then that will use a lot of CPU.
Show the code and we will tell
Code: Select all
while [ 1 ];
do
sudo sh /home/pi/exitfix.sh & /home/pi/exitfix2.sh
sleep 1;
done
Code: Select all
#!/bin/bash
find /home/pi/.kodi/temp/kodi.log -type f -exec egrep -w "Attempted to remove window 10013" {} \; > /home/pi/exitfix2.txtCode: Select all
exitfix=$(cat /home/pi/exitfix2.txt| awk 'NR==1' | tail -c 6)
if [ $exitfix = "exist" ]; then
sudo killall /usr/lib/kodi/kodi.bin && sudo rm -r /home/pi/exitfix2.txt /home/pi/.kodi/temp/kodi.log
fiCode: Select all
/home/pi/exitfix2.sh: 2: [: =: unexpected operator
find: `/home/pi/.kodi/temp/kodi.log': No such file or directoryCode: Select all
sudo sh /home/pi/exitfix.sh && /home/pi/exitfix2.sh
Ok thanks I will put that and see..PeterO wrote:I think you probably want
Then the second script will only be run if the first one returns "true"Code: Select all
sudo sh /home/pi/exitfix.sh && /home/pi/exitfix2.sh
PeterO