public inbox for linux-newbie@vger.kernel.org
 help / color / mirror / Atom feed
From: AD Marshall <admarshall@gmail.com>
To: linux-newbie@vger.kernel.org
Subject: how-to: one command for repeat OR iterate shell OR bash command delay OR interval
Date: Sun, 17 Jul 2005 11:57:34 +0700	[thread overview]
Message-ID: <200507171157.35066.admarshall@gmail.com> (raw)

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

             reply	other threads:[~2005-07-17  4:57 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-07-17  4:57 AD Marshall [this message]
2005-07-17  5:35 ` how-to: one command for repeat OR iterate shell OR bash command delay OR interval John Kelly
2005-07-17  6:07   ` AD Marshall
2005-07-17  6:16     ` AD Marshall
2005-07-19  3:24       ` [Solution] " AD Marshall

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200507171157.35066.admarshall@gmail.com \
    --to=admarshall@gmail.com \
    --cc=linux-newbie@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox