Hi,
I'm trying to write a while loop that will search for "[JkMain] Jk running" in temp.out file
if the word is not there then I want to keep looping until it's there then I want to exit the loop.
I'm not sure what to do please help.
Thank you.
Here is what I have so far.
while check=`grep "*[JkMain] Jk running" | wc -l`
do
if [ $check -gt 0 ]
then
echo " Jk running is in temp.out"
exit
fi
done < nohup.out
until fgrep "[JkMain] Jk running" temp.out >/dev/null&&\
echo "Jk running is in temp.out"; do
sleep 10
done
radoulov,
This might be a silly question but why are we sending it to dev/null?
Otherwise you'll get the matched pattern on the screen (assuming your grep doesn't support the q option):
$ until fgrep "[JkMain] Jk running" temp.out >/dev/null&&\
> echo "Jk running is in temp.out"; do
> sleep 1
> done
Jk running is in temp.out
$ until fgrep "[JkMain] Jk running" temp.out&&\
> echo "Jk running is in temp.out"; do
> sleep 1
> done
[JkMain] Jk running
Jk running is in temp.out
If you're on Linux or Solaris (using grep under /usr/xpg4/bin) you could avoid the redirect:
$ alias grep=/usr/xpg4/bin/grep
$ until grep -Fq "[JkMain] Jk running" temp.out&&\
> echo "Jk running is in temp.out"; do
> sleep 1
> done
Jk running is in temp.out