Reputation:
Hi im working on a simple bash coding i don't know how to accomplish this and this might be easy for you guys please help.
I have a simple program on file.sh
#!/bin/bash
./program
This ./program is a compiled version of C program which i complied using GCC im trying to use at in bash script to execute this program for few seconds and then terminate that after x interval time and restart again.
I hope you got my point?
Example: Run file.sh for 10 sec and I'll display the result from ./program C program and then after 10 sec it will restart again.
Upvotes: 0
Views: 517
Reputation: 46
You can use the sleep
command. For example: exec ./program && sleep n
where n is the time you want the command to sleep. If you want you could put it in a while loop inside an sh
script and run it continuously.
To run it continuously until you close the terminal:
while true
do
echo "[CTRL+C] to stop..."
timeout 10s ./program
done
Upvotes: 0
Reputation: 4969
The answer is, if I understand correctly, a combination of sleep
and timout
:
while :; do
timout 10s ./program
# display some results
sleep 10
done
Upvotes: 2