Simple repeating command-line command

Simple repeating command-line command

Rather than write a script for something you may only need once, there’s an easy way to repeat a series of command-line commands. This works in bash and may in other shells:

while [ 1 ]; do <some command>; <some other command>; sleep <some delay in seconds>; done;

So, for example:

while [ 1 ]; do date; uptime; sleep 10; done;
This will generate:
Mon Mar 19 13:20:30 PDT 2018
13:20 up 1:23, 3 users, load averages: 3.25 3.87 3.51
Mon Mar 19 13:20:40 PDT 2018
13:20 up 1:24, 3 users, load averages: 3.31 3.86 3.51
Mon Mar 19 13:20:50 PDT 2018
13:20 up 1:24, 3 users, load averages: 5.44 4.30 3.67

Just use Ctrl-C to end.

Extra credit

Add a counter so that it runs 10 times only:

for n in $(seq 1 10); do date; uptime; sleep 10; done