Use a crontab job to call your script.
Add the following line
* * * * * /path/to/your/script
This wil execute your script every minute. You can check here how to customize for other execution times. Crontab man page
Sorry that I missed the requirement to run every 5 secs. But like Jonnhy mentioned in the comments, you can have the cronjob verifying if the script is running or not.
Script for crontab:
ps -ef|grep -v grep |grep script_name
if [ $? != 0 ]; then
In your script:
while true; do
#perform the test
Or if you are using a linux that is still based on init scripts, you can perhaps a entry to /etc/inittab
Although I'm not really sure if it is a best practice to have this in inittab.
If your system is already with systemd, there is also a way to perform this, but I don't have experience with it to put it here.