Scrip shutdown for esxi host when ping failed

Good day everyone.
I have follow the solution in this topic to make the scrip for shutdown esxi host. (Bash Script If Ping Fails Then Automatically Reboot Server - Computer How To)


# Set target host IP or hostname

count=$(ping -c 3 $TARGET_HOST | grep from* | wc -l)

if [ $count -eq 0 ]; then
    echo "$(date)" "Target host" $TARGET_HOST "unreachable, Rebooting!" >>/var/log/inetmonit.log
    /sbin/shutdown -h now

    echo "$(date) ===-> OK! " >>/var/log/inetmonit.log

but when I add it to crond in my ESXi host it not work. and I don’t know how to check it. and I don’t know to rotation the log file

Could you please help me to this. Thank you so much