Tech Reflect
  • Home
  • About This Site
  • Contact me
  • Search Icon
Simple repeating command-line command

Simple repeating command-line command

2018-03-19

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

Related Posts:

  • Why is my own data least important in search?
    Why is my own data least important in search?
  • Ultra high volume email workflow
    Ultra high volume email workflow
  • Old Dock tips that are still useful
    Old Dock tips that are still useful

geeky, macOS tips

Post navigation

NEXT
Quick open files of a certain type
PREVIOUS
Flow control in bash

Get Monthly Updates

Recent Posts

  • Flower Power and Blue Dalmatian to the rescue?
  • “Why does Mail have to be so fucking complicated?”
  • This mouse has no tail!
  • Interview feedback and the Thumb-o-meter™
  • Buy a cactus, get hired

Categories

  • analog (1)
  • apple career (11)
  • apple inside (11)
  • apple stories (17)
  • bertrand serlet (3)
  • essays (15)
  • geeky (21)
  • interviews (4)
  • iOS tips (3)
  • Mac OS X (2)
  • macOS tips (37)
  • personal (7)
  • products (4)
  • scott forstall (7)
  • scripting (1)
  • steve jobs (14)
  • tim cook (1)
  • workplace (14)

Get Monthly Updates

About cricket


Me with Guiness the owl

25 years in tech. I like to write manifestos. I like to offer interesting tips. I like making fun of things. Everyone copes differently.

My Other Blogs

  • Free Range Parrots
  • Plucky Tree (personal)
© 2022   All Rights Reserved.