public inbox for linux-newbie@vger.kernel.org
 help / color / mirror / Atom feed
* how-to: one command for repeat OR iterate shell OR bash command delay OR interval
@ 2005-07-17  4:57 AD Marshall
  2005-07-17  5:35 ` John Kelly
  0 siblings, 1 reply; 5+ messages in thread
From: AD Marshall @ 2005-07-17  4:57 UTC (permalink / raw)
  To: linux-newbie

Is there already one bash command to do what the following script does (poorly or incompletely), ie repeat "command" indefinitely every "x" seconds:

#!/bin/sh
# usage: repeat [x] <command>
while true ; do $2 ; sleep $1 ; done


if not, and you want to use the above in a script of your own, just copy the above 3 lines and do the following (typing the lines into the console or pasting them in shell, using konsole under kde or gpm under a tty shell; hit <Ctrl-c> to stop it from looping). The two examples are optional. The stuff in angle brackets, <>, is stuff you won't see in your shell output:

am@[bin]$ cat >repeat
#!/bin/sh
# usage: repeat [x] <command>
while true ; do $2 ; sleep $1 ; done
am@[bin]$ chmod +x repeat
<examples>
am@[bin]$ ./repeat 2 "cat /proc/loadavg"
0.46 0.92 1.72 9/125 24171
0.46 0.92 1.72 2/125 24173
0.59 0.94 1.72 1/125 24181
<Ctrl-c>
am@[bin]$ cd ..
am@[~]$ repeat 2 uname
Linux
Linux
<Ctrl-c>

btw: i've already posted the same to:
http://www.linuxquestions.org/questions/showthread.php?s=&threadid=343892

some answers might show up there before i get back 

-- 
AD Marshall
Tel:  +84 (0)903871313
eM:   admarshall@gmail.com
Web:  http://h0lug.sourceforge.net
Zone: ICT (IndoChina Time; GMT/UTC+7)
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2005-07-19  3:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-07-17  4:57 how-to: one command for repeat OR iterate shell OR bash command delay OR interval AD Marshall
2005-07-17  5:35 ` John Kelly
2005-07-17  6:07   ` AD Marshall
2005-07-17  6:16     ` AD Marshall
2005-07-19  3:24       ` [Solution] " AD Marshall

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox