I guy!
I need an help...
I will try to create a monitoring bash script that ping our apparate and send mail if it go offline.
I need to use a list of apparates that have 3 column (name, ip gataway, ip address) and n row.
That file (list.txt) is like that:
Code:
server1 30.30.30.1 30.30.21.1
server2 30.30.30.2 30.30.21.2
server3 30.30.30.3 30.30.21.3
My bash script is:
Code:
#!/bin/bash
#Check IP
for i in $(cat list.txt | awk '{ print $2}')
do
#n=$(cat lista | awk '{ print $1}')
ping -c 1 -w 1 $i &> /dev/null
if [ $? -ne 0 ]; then
echo "GW $i DOWN!"
fi
done
This script run, but the $i variable is the GW address.
I need to insert in echo "GW $i DOWN!" not the GW address (column 2), but the name of the server (column 1)
If i remove the comment on #n=$(cat lista | awk '{ print $1}') and insert the variable $n in the "echo" (echo "GW $n DOWN!") the output is the list of the column 1...
I need also insert the check of the 3th column... and the alert mail!
Can you help me please?
I want to have this output
"GW server2 DOWN!" check it every 15 min (i can insert it in crontab) and then send it to email address
Thank you for your help!