How to make animals run from players

When player attacks an animal, every animal near of that animal start to run. I am wondering how to make this with commands.

Continue to help post