This article will teach you how to create a looped command in linux, that will run permanently in the background. The only requirement for this is that you are able to enter commands into a linux terminal.
Create your file
- Create an empty file called loop.sh with `touch loop.sh`
- Begin editing the empty file - `nano loop.sh`
- Enter the contents of below, replacing the very obvious `mycommandhere` with your command. Any other commands you might need to run afterwards can be placed on the next line.
#!/bin/bash while true do mycommandhere sleep 1 done
- Run it once with `bash loop.sh`. If that doesn't work, you might have to directly use `/bin/bash loop.sh`
- If you don't need an easy way to stop or restart it, you can send it off to the background with `/bin/bash/loop.sh &>/dev/null &`. This is an extremely carefree way of handling it, so be careful with running this.
With the above approach, there's a limited amount of ways that it can be terminated. There are much more elegant and preferrable solutions that might fit your use case better: