Question

I'm building an interface to basically list computers on my local network that are 'alive' and more or less have a list of these nodes, and their 'status'.

I've created a file called farm_ping.sh located under /Volumes/raid/farm_scripts/_apps/_scripts/farm_ping.sh

This file contains the following, which simply pings the IP and writes it's result to a txt file also named by the given IP:

HOSTS="192.168.1.110"

# no ping request
COUNT=1

for myHost in $HOSTS
do
  count=$(ping -c $COUNT $myHost | grep 'received' | awk -F',' '{ print $2 }' | awk '{ print $1 }')
  if [ $count -eq 0 ]; then
    # 100% failed     
    echo "Host : $myHost is down (ping failed) at $(date)" > /Volumes/raid/farm_script/nodes_response/$myHost.txt
  else
    # 100% Passed
    echo "Host : $myHost is running (ping successful) at $(date)" > /Volumes/raid/farm_script/nodes_response/$myHost.txt
  fi
done

I want this to run this script every minute, here's what I have done to create a cron job:

env EDITOR=nano crontab -e

And in the cron job I wrote:

1 * * * * /Volumes/raid/farm_script/_apps/_scripts/farm_ping.sh

I saved this file, but it's been 30 mintues, and nothing has written yet, what have I done wrong?

Was it helpful?

Solution

Issue was cronjob syntax.

1 * * * * 

In context, * means every possible value and a number means a particular time. So this literary means the 1st minute of every hour of every day of every month of every week day.

Replacing the the 1 with a * makes it run every minute.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top