• Skip to main content
  • Skip to header right navigation
  • Skip to site footer
  • YouTube
  • MakerWorld
  • Instagram
  • Threads
  • Bluesky
  • Mastodon
  • Facebook
makerhacks-logo

Maker Hacks

Ideas, news & tutorials for makers and hackers – Arduino/Raspberry Pi, 3D printing, robotics, laser cutting, and more

  • Home
  • About
  • 3D Printing
  • Laser Cutting
  • CNC
  • Programming
  • Free Arduino Course
  • Free Robotics Course
  • Recommendations

Linux Automation Tip: Repeat Commands with Loops and Delays

You are here: Home / Software and Programming / Linux Automation Tip: Repeat Commands with Loops and Delays
Author: Chris Garrett

Unix and Linux are a lot more powerful for automation than people from other operating systems know, that power is under the hood in Macosx (via the BSD Unix foundations) and that power is making its way into Windows in a big way too. Let’s take a look at one simple example …

You might have seen my Python script for creating thumbnails.

What if I wanted to run it continuously?

Well, Linux has an app for that ;)

Create a new file and call it something like “do-thumbs.sh“. Add the following to the file then save:

#!/bin/bash

while [ 1 ];
do
    python3 thumb.py
    sleep 60s
done

Now enter

chmod +x do-thumbs.sh

This will make your Shell Script executable.

Now if you run the script using

./do-thumbs.sh

It will repeat forever!

Sleep

Note we delay with the sleep command so that we are not pounding the machine.

Sleep can take several time delay options – specify the delay in seconds, minutes, hours or days.

s – seconds
m – minutes
h – hours
d – days

Repeat for a Fixed Count Using For Loops

What if you don’t want it to loop forever?

Just replace the while line with

for x in {1..10}

Category: Software and ProgrammingTag: automation, Hacks, linux, tips

About Chris Garrett

Marketing nerd by day, maker, retro gaming, tabletop war/roleplaying nerd by night. Co-author of the Problogger Book with Darren Rowse. Husband, Dad, 🇨🇦 Canadian.

Check out Retro Game Coders for retro gaming/computing.

☕️ Support Chris on Ko-Fi to get exclusive content and rewards!

Previous Post:Beautiful prints off the Formlabs Form 2Formlabs Form 2 First Look
Next Post:Email Your Raspberry Pi IP Address on Bootpi-ip

Sidebar

  • Facebook
  • Instagram
  • YouTube

Featured Posts

  • CyberBrick Review + Getting Started
  • xTool M2 Review
  • xTool F2 Ultra Review
  • xTool F2 Review
  • xTool S1 Review
  • Anycubic Kobra S1 Combo Review
  • Makera Z1 Pro Review
  • CNC Buyer's Guide
  • eufyMake E1 UV Printer Review
  • eufyMake Purifier P1
  • Z80 on a Breadboard
  • OpenSCAD MakerWorld Customizer

30 Days to Arduino

Arduino Tutorials
  • 3D Printing
  • CNC
  • Electronics and Hardware
  • Laser Cutting
  • News and Reviews
  • Software and Programming

arduino budget cad cnc diode laser glowforge Hacks Ideas laser cutter linux Makes making python raspberry pi Reviews technology tips xtool xTool Lasers

  • YouTube
  • MakerWorld
  • Instagram
  • Threads
  • Bluesky
  • Mastodon
  • Facebook

.

Maker Hacks Blog Copyright © 2026 · All Rights Reserved · Privacy Policy