How to create a looped command in linux, that will run permanently in the background.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
SokenDev fda6a5f68a Update 'README.md' 8 months ago
README.md Update 'README.md' 8 months ago

README.md

LinuxLoop

How to create a looped command in linux, that will run permanently in the background.
You must have a basic understanding of Linux to be able to follow this tutorial. I will not help with basic requests such as "how do I change directory".

Creating your loop file

  1. touch loop.sh - Creates an empty file called loop.sh in the current directory.
  2. nano loop.sh - Opens the file in the nano editor, feel free to use vim or your other favourite text editor.
  3. Enter your contents:
#!/bin/bash
while true
do
    mycommandhere
    sleep 1
done
  1. Replace mycommandhere with your command. It may be python run.py or something else, but make sure you take into account file paths when specifying where a file is.
  2. Run it to ensure it works: bash loop.sh or /bin/bash loop.sh.
  3. Send it off to the background however you like. You can simply use /bin/bash loop.sh &>/dev/null &. There are some caveats with this, so here's some links: