Hello,
I'm trying to make script with bash so I want to gain more experience with this super tool.
I've trying to make a host script to make job more effective and faster.
#!/bin/bash
#By Rokas Klyvis
echo "Iveskite adresa arba IP"
read hostname
host $hostname
host www.$hostname
host mail.$hostname
whois $hostname | grep -E 'Domain:|Nameserver:|Status:|Registrar:'
PACKETS=1
for myHost in $hostname
do
check=$(ping -c $PACKETS $myHost | grep 'received' | awk -F',' '{ print $2 }' | awk '{ print $1 }')
if [ $check -eq 0 ]; then
echo "Hostname : $myHost nepingina"
else
echo "Hostas pingina OK"
fi
done
So for example, if I put domain, that doesn't exist, this script gives error ./host.sh: line 16: [: -eq: unary operator expected
I understand, that awk cutting doesn't help anymore, tried to make if statements with != ping: unknown host $myHost but still no luck, I just need to make, if host doesn't exists, just to show single line "Host doesn't exist" and that's it. It should be useful for many sysadmins so would be lovely to get your pros help for such newbies like me
Regards.