How to implement a command n times?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to implement a command n times?
# 1  
Old 05-23-2011
How to implement a command n times?

I need to run a command n (n >= 100) times and the command running may take about 30 seconds. Can anyone help me with the shell script to achieve this? Thanks in advance.
# 2  
Old 05-23-2011
Try:

Code:
for ((i=0;i<$n;i++))
do
command
done

# 3  
Old 05-23-2011
Thanks for reply! But the problem is the command here is a C++ executable file which takes about 30 seconds to run so before the current command running completes the next running should not start. Thanks!
# 4  
Old 05-23-2011
Did you give it a try? The shell won't continue the loop (and thus start the command again) until the previous run did end, unless you explicitly tell it to run the command in the background.
# 5  
Old 05-23-2011
something like

Code:
#!/usr/bin/ksh
i=0
while [ $i -lt 100 ]
do
    let i+=1
    yourcommand &
    wait $!
done

# 6  
Old 05-23-2011
We are confused here. You want multiple instances to run parallel or in sequential ?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to implement a simple command/code for multiple files?

I have been extracting a row, based on multiple key word from a xls/csv file, by using the following command. I have to implement the same for multiple xls/csv files, therefore please help me to do the same. awk ' { tbp=0 if ($0 ~ keyword1 && k1 == 0) { tbp=1; k1++ } if ($0 ~ keyword2... (2 Replies)
Discussion started by: dineshkumarsrk
2 Replies

2. Shell Programming and Scripting

sed command to replace one value which occurs multiple times

Hi, My Input File : "MN.1.2.1.2.14.1.1" := "MN_13_TM_4" ( 000000110110100100110001111110110110101110101001100111110100011010110111001 ) "MOS.1.2.1.2.13.6.2" := "MOS_13_TM_4" ( 000000110110100100110001111110110110101110101001100111110100011010110111001 ) Like above template,I have... (4 Replies)
Discussion started by: Preeti Chandra
4 Replies

3. Programming

Implement ps command in C

Hello, could anybody explain how the ps command works? I know something about the proc file system. But I'm still not sure about how it exactly works. Like ps without any option will print out the current user's processes, but it never displays my web browsers such as firefox or my LibreOffice... (3 Replies)
Discussion started by: freedombird9
3 Replies

4. Homework & Coursework Questions

How to implement wc command using awk?

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Here in flwng code \n is not working 2. Relevant commands, code, scripts, algorithms: Files: a.txt This... (0 Replies)
Discussion started by: sidpatil
0 Replies

5. Shell Programming and Scripting

Script runs in command-line fine but times out in CRON?

Hi, I have a script that seems to run to completion when in the command-line, but when it is run using the cron, it seems to time out. They both start and run fine, but on the CRON it stops prematurely. The script hits an API every few seconds and grabs data. Does anyone have any idea on... (4 Replies)
Discussion started by: phpchick
4 Replies

6. Programming

Problem with implementing the times() function in C (struct tms times return zero/negative values)

Hello, i'm trying to implement the times() function and i'm programming in C. I'm using the "struct tms" structure which consists of the fields: The tms_utime structure member is the CPU time charged for the execution of user instructions of the calling process. The tms_stime structure... (1 Reply)
Discussion started by: g_p
1 Replies

7. Shell Programming and Scripting

Run .command at specific times

Okay so I've got a command to start my java server up, but I want it to start at say 8:00AM and then stop at 11:00PM. In order to stop it I have to type stop and press enter in the terminal. I've been trying to get this to work and I'm having no luck. Here's my command: #!/bin/bash cd "`dirname... (2 Replies)
Discussion started by: JustChillin1414
2 Replies

8. Shell Programming and Scripting

Command That Gives Booting Times

hi friends, ım new in shell scripting and ı want to know that which commands gives the booting times in fixed time interval(day) ı have entered. For Example, When ı enter 4 for command, Command will return the booting times in last 4 days. Thank for your helps!!! (9 Replies)
Discussion started by: deco
9 Replies

9. Shell Programming and Scripting

Trying to implement 'more' command

Hi all, i'm quite new in the UNIX world. So maybe i'm going to ask simple questions but they are unsolvable for me... I'm trying to implement the 'more' function or kinda of that, for improving my knowledges. But I encountered some problems that i hope u will help me to solve. The code i... (0 Replies)
Discussion started by: Cellofan
0 Replies

10. Shell Programming and Scripting

How to make my command work at all times

hi all, This is a very basic question. I want to make the command work at all times. i'm working on Suse-Linux and "clear" command is used to clear the contents of screen. I want to use only "cls" instead of "clear" command. i tried alias cls=clear , but its working only for a temporary... (3 Replies)
Discussion started by: wxwidgets
3 Replies
Login or Register to Ask a Question