First time with loops!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting First time with loops!
# 1  
Old 12-01-2010
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..

Code:
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
# 2  
Old 12-01-2010
Code:
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

Code:
done
fi

is wrong, it should be
Code:
fi
done

instead

Last edited by ctsgnb; 12-01-2010 at 03:09 PM..
This User Gave Thanks to ctsgnb For This Post:
# 3  
Old 12-01-2010
I'm a bit embarassed that I couldn't figure this easy one out, thanks : ) Smilie
# 4  
Old 12-01-2010
bt way the trailing
Code:
done
fi

is buggy : it should be
Code:
fi
done

instead
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Need help with for loops

Why wont my for statements work? Im trying to get this script to swich to a user an if you put in a start/stop/or restart paramater to do just that for each user. I commented out the actual start/stop actions to test it just by using echos and not do anything hasty in the environment but it... (0 Replies)
Discussion started by: LilyClaro
0 Replies

2. Shell Programming and Scripting

Loops

Hi All, I am very new to Shell scripting. I read basic scripting manual. But i didn't understand the code. Please tell the meaning of the below code: while getopts "F:f:R:r:C:c:" opt 2>/dev/null do case ${opt} in F|f) FREQUENCY_MODE=$OPTARG;; ... (3 Replies)
Discussion started by: pdathu
3 Replies

3. UNIX for Dummies Questions & Answers

For Loops

Hi everyone, I have a question regarding for loops. I am writing a BASH shell script that will contain multiple loops. These loops all involve looping with a count: for (( a=0; a <=10; a++ )); do echo $a done If none of my multiple loops relate to each other throughout the script,... (3 Replies)
Discussion started by: msb65
3 Replies

4. Shell Programming and Scripting

trying to learn for loops, and arrays at the same time

Ok, I've already completed the task this is for, but now I'm trying to go back and find more eloquent solutions for future reference. I have a report I've generated that is formatted like this: 1033 1 1079 4 1453 5 2205 6 1933 7 461 8 646 9 1655 12 975 13 1289 14 The first number is... (3 Replies)
Discussion started by: DeCoTwc
3 Replies

5. Shell Programming and Scripting

Help with the 2 for loops

#!/bin/bash IFS=$'\n' A= a c b t g j i e d B= t y u i o p counter=0 found="" for i in $(cat $A) do for j in $(cat $B) do if then found="yes" fi done if then (1 Reply)
Discussion started by: vadharah
1 Replies

6. UNIX for Dummies Questions & Answers

Help with While Loops

I am traversing down a list, and I am not quite sure how to tell the loop to break when it's done going through the file. #!/bin/sh while : do read list <&3 echo $list done is the code. The file "list" is simply 5 4 3 2 1 any advice on how to break the loop after the file is... (1 Reply)
Discussion started by: MaestroRage
1 Replies

7. Shell Programming and Scripting

Loops within loops

I am running on HPUX using ksh. I have a script that uses a loop within a loop, for some reason the script seems to hang on a particuliar record. The record is fine and hits the condition in Blue. If I kill the 1st loop process the script continues on with no problem. Begin code> <Some... (8 Replies)
Discussion started by: bthomas
8 Replies

8. UNIX for Advanced & Expert Users

Loops

Can anybody help please. I am trying to right a script which will loop until a certain action has been performed. For example i current have two batch jobs i would like to put into a wait status. Batch Jobs A and B . The script i am trying to get to work is below. jobs="A B" COUNT=0 while... (2 Replies)
Discussion started by: mariner
2 Replies

9. Shell Programming and Scripting

loops in loops

ok, i tried to write a script called purge.sh which searches current process' for a specified user running a process with a specified keyword. it also prompts the user to see how many times to purge for the specified process and how many different processes they wish to do this to.it worked until... (11 Replies)
Discussion started by: Blip
11 Replies

10. UNIX for Dummies Questions & Answers

While loops

Hi all, I am an amateur k shell scripter and came across something I need clarification on. while ; do various commands done What is the "" condition testing for in the above while loop? THx, Bookoo (5 Replies)
Discussion started by: bookoo
5 Replies
Login or Register to Ask a Question