First time with loops!

My script that I have gotten much help with on here is almost complete..

I need to add a loop, to try a script 4 times, after the 4th time, just stop..

do
 
 
auth=$(ps -ef | grep [a]uth | awk '{ print $2}')
if [ -n "$auth" ]
 then
      echo "Process is running"
  
  ps=$(ps -ef | grep ps | awk '{ print $2}')
   if [ -n "$ps" ]
    then
         
         echo "Start All Processes"
     ###START process script 
    else
         echo "Starting Authentication".
     cd /home/dir/app
     sleep 10
     ###START process script 
   fi

   
 else
      echo "Something....then try again 4 times then quit."
  sleep 30
 
done
fi

thanks in advance

for i in 1 2 3 4
do
echo "Task execution number $i"

... do whatever you want ...

done

by the way you have an error : the trailing

done
fi

is wrong, it should be

fi
done

instead

1 Like

I'm a bit embarassed that I couldn't figure this easy one out, thanks : ) :b:

bt way the trailing

done
fi

is buggy : it should be

fi
done

instead