How to terminate a tail -f

I am developing a script with a tail -f in it. My problem is how to terminate it and execute the next line.

It depends!

Why are you using tail -f in the first place? I imagine to print out something like a log file as it is being written. In that case you need to first ask yourself how do you know you are finished with the tail command - when the process writing to the file has finished?

I would not use "tail -f" in a script. But you could launch it in the background, save the pid of the background job, sleep for a while, then kill the background job.

I agree the tail in a script isn't such a flash method.... what is it you are trying to acheive? I'm sure we can come up with a better option.

Thanks for your advice.

My problem is actually not a tail -f but it actually works just like it.

There is this system that is being used here in our company wherein we can check connectivity of server to server by a send and listen commands.

The thing is if we activate the listen command, it will not terminate automatically when it recieves the data from the sender unless we terminate it manually.

I was just thinking that if we could terminate such command by script, I can make a script wherein I can check connectivity for multiple boxes at the same time.