Answer the question
In order to leave comments, you need to log in
Execute script every 5 seconds Linux
Hello. It is necessary that the script /var/filter.sh be run every 5 seconds without any commands. Those. I launched it once after rebooting the OS, and then it was already hanging in the processes and being executed.
Answer the question
In order to leave comments, you need to log in
I remembered:
# watch --interval=5 /var/filter.sh
another useful application watch
nsk.lug.ru/poleznye-sovety/poleznye-sovety-komanda...
www.opennet.ru/man.shtml?topic=watch&category =1&ru...
You can pipe the output to /dev/null
# watch --interval=5 /var/filter.sh > /dev/null
Not exactly what you want, but take note.
Runs your script at intervals of 5 seconds.
The only thing to keep in mind is that if your script does not have time to execute in five seconds, then there may be an effect of "avalanche birth of new processes". It can especially arise if the script uses locks.
And sleep is very easy en.wikipedia.org/wiki/Sleep
/var/filter.sh
#!/bin/sh
echo "Начинаем..."
while (true)
do
echo "Ваш скрипт";
sleep 5; # пауза 5 секунд
done;
In general, there is snaked for this.
But if we are to make crutches, then:
#!/bin/bash
while :; do sleep 5; flock -n /tmp/lock1 -c /var/script.sh & done
Either in cron, or the body of the script into an infinite loop, at the end (beginning) of which there is a delay (sleep 5).
The second option is more convenient, since it is much easier to unload the script (just kill it, and not cut it out of cron), and also run it again after cutting it out. Yes, and it is more suitable for the conditions specified in the formulation of the question (it may not start automatically after a reboot, if not set to autoload).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question