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}