how to execute a while loop for 20 minutes?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers how to execute a while loop for 20 minutes?
# 1  
Old 07-05-2007
how to execute a while loop for 20 minutes?

I want to execute a while loop (or any other loop) for 20 minutes.

I have extracted the minutes and seconds from the current system date by using the command y = `date +%M%S`

How to proceed ??
# 2  
Old 07-05-2007
I would try something like
Code:
#! /usr/bin/ksh
secs=$(perl -e 'print time(), "\n"')
((targetsecs=secs+20*60))
while ((secs < targetsecs)) ; do
        sleep 5
        echo running
        secs=$(perl -e 'print time(), "\n"')
done
echo done
exit 0

# 3  
Old 07-05-2007
Is this a right approach?

Code:
#!/bin/ksh
SECONDS=0
while [[ SECONDS -lt 1200 ]] ; do
 echo $SECONDS
done

Thanks
nagarajan G
# 4  
Old 07-05-2007
Bug It worked for 20 minutes

Quote:
Originally Posted by Perderabo
I would try something like
Code:
#! /usr/bin/ksh
secs=$(perl -e 'print time(), "\n"')
((targetsecs=secs+20*60))
while ((secs < targetsecs)) ; do
        sleep 5
        echo running
        secs=$(perl -e 'print time(), "\n"')
done
echo done
exit 0


Thanx Perderabo !!!!!!!!!!!
# 5  
Old 07-05-2007
Quote:
Originally Posted by ennstate
Is this a right approach?

Code:
#!/bin/ksh
SECONDS=0
while [[ SECONDS -lt 1200 ]] ; do
 echo $SECONDS
done


It works if u r sure that 1 complete execution of the loop takes exactly 1 second. if the no. of statement is more then it may take more than a second to execute the loop once.
# 6  
Old 07-05-2007
Quote:
Originally Posted by ennstate
Is this a right approach?

Code:
#!/bin/ksh
SECONDS=0
while [[ SECONDS -lt 1200 ]] ; do
 echo $SECONDS
done

Thanks
nagarajan G
I like that solution better than mine because it does not need perl.
# 7  
Old 07-05-2007
Quote:
Originally Posted by subhotech
It works if u r sure that 1 complete execution of the loop takes exactly 1 second. if the no. of statement is more then it may take more than a second to execute the loop once.

It doesnot depend on the number of statements that are executed in the while loop.But it depends on the number of SECONDS spend since the shell invocation.

man ksh says,
Quote:
SECONDS
Each time this variable is referenced, the number of seconds since shell invocation is returned. If this variable is assigned a value, then the value returned upon reference will be the value that was assigned plus the number of seconds since the assignment.
Thanks
Nagarajan G
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Check file creation Time minutes and if file older then 5 minutes execute some stuff

Hello all, Info: System RedHat 7.5 I need to create a script that based on the creation time, if the file is older then 5 minutes then execute some stuff, if not exit. I thought to get the creation time and minutes like this. CreationTime=$(stat -c %y /tmp/test.log | awk -F" " '{ print... (3 Replies)
Discussion started by: charli1
3 Replies

2. Shell Programming and Scripting

Grep a log file for the last 5 minutes of contents every 5 minutes

Hi all, System Ubuntu 16.04.3 LTS i have the following log INFO 2019-02-07 15:13:31,099 module.py:700] default: "POST /join/8550614e-3e94-4fa5-9ab2-135eefa69c1b HTTP/1.0" 500 2042 INFO 2019-02-07 15:13:31,569 module.py:700] default: "POST /join/6cb9c452-dcb1-45f3-bcca-e33f5d450105... (15 Replies)
Discussion started by: charli1
15 Replies

3. UNIX for Beginners Questions & Answers

How to convert days hours minutes seconds to minutes?

Hi, please help with below time conversion to minutes. one column values: 2 minutes 16 seconds 420 msec 43 seconds 750 msec 0 days 3 hours 29 minutes 58 seconds 480 msec 11 seconds 150 msec I need output in minutes(total elapsed time in minutes) (2 Replies)
Discussion started by: ramu.badugula
2 Replies

4. Shell Programming and Scripting

How to execute a command inside a while loop?

How do we execute a command inside a while loop? (7 Replies)
Discussion started by: Little
7 Replies

5. Shell Programming and Scripting

Execute command with loop

I have a below command ALTER TABLE `abc` ADD PARTITION ( PARTITION 20130613 VALUES less than (DAY('13'))); Below is requirement It runs in Loop as DAY start with 13 and end with 100 along with this of counter "20130613" also increases per command as the next command should be ... (8 Replies)
Discussion started by: kaushik02018
8 Replies

6. UNIX for Dummies Questions & Answers

unable to execute while loop

Hi everyone. I wanted to print numbers from 1 to 5 in reverse order. For this I used the following code: #!/bin/bash x=5 while do echo $x x=`expr $x - 1` echo "" done echo "" Well but on compiling the above code, it gives the following error. ... (3 Replies)
Discussion started by: grc
3 Replies

7. UNIX for Advanced & Expert Users

Execute while loop

Hi, I have a background process running for which I want to know the status continuously. I want to execute a WHILE loop in the command prompt so that it keeps on displaying in the screen.But, I am getting the following errors :- hyper20:~ 3> while while? while? hyper20:~ 4> while {1}... (7 Replies)
Discussion started by: shubhranshu
7 Replies

8. Shell Programming and Scripting

Execute Loop in Telnet

hi Everyone , have a nice day #!/bin/sh ( sleep 1 echo "LOGIN:username:password;" sleep 1 while IFS= read -r line do #echo $line GET:VOUCHERDETAIL:VoucherSerialNumber,$line; >> /home/status_log done < /home/status.txt sleep 1 echo "LOGOUT;") | telnet 127.0.0.1 7021 , it... (2 Replies)
Discussion started by: Dastard
2 Replies

9. Shell Programming and Scripting

loop does not execute in bash script?

I have a very basic bash shell script, which has many "while... done; for .... done" loop clauses, like the following ~~ #!/bin/bash while blablalba; do .... done < /tmp/file for line in `cat blablabla`; do grep $line /tmp/raw ; done > /tmp/1; while blablalba2; do .... done <... (2 Replies)
Discussion started by: fedora
2 Replies

10. Shell Programming and Scripting

Execute commands parallel in a for loop ?

Hi, please can someone point me in the right direction with a shell scripting problem. I want to execute a command in a for loop and the command should be started not one-by-one meaning the for loop is waiting for the exit code , it should be started in parallel. I have a plain text file... (3 Replies)
Discussion started by: networkfre@k
3 Replies
Login or Register to Ask a Question