sh script sa v crontabe spusti nekorektne
Dobrý deň,
spravil som si sh scriptik, ktory mi pinguje ipadresy, ktore mam ulozene v subore ipadresy. Pokial ho spustim normalne teda ./new.sh vsetko funguje ako ma. Dal som ho nech sa mi spusta cronom kazdu minutu teda
*/1 * * * * /home/etharendil/new.sh
Teraz mi vznikol problem, ze do /var/www/kontrola.html sa mi zapise iba text "kontrola DNS prebehla..." a nekontroluje mi ip v subore ipadresy
/home/etharendil/new.sh :
#!/bin/sh
# premenne
logfile=/var/log/chybne.log
kfile=/var/www/kontrola.html
if [ -f $logfile ] ; then
rm $logfile
fi
for name in `awk '{print $1}' ipadresy`
do
ping -q -w 2 $name >/dev/null
if [[ $? != 0 ]]; then
echo Teraz nefunguje `grep "$name" ipadresy` cas nefunkcnosti: `date '+%Y-%m-%d %H:%M:%S '` >> $logfile
else
touch $kfile
echo -e "`date '+%Y-%m-%d %H:%M:%S'` Kontrola `grep "$name" ipadresy` v poriadku" >> $kfile
# grep $name ipadresy | awk '{print $2}'
fi
done
# DNS test
nslookup www.google.sk | grep "server can't find" >/dev/null
if [[ $? = 0 ]] ; then
echo Nefunguje DNS server >> $logfile
else
echo -e "`date '+%Y-%m-%d %H:%M:%S'` Kontrola DNS prebehla v poriadku\n" >> $kfile
fi
# Zaslanie mailu o chybe
if [ -f $logfile ]; then
ssh etharendil@10.232.129.5 mail -s "Chyby" admin@sk.rhenus.com < $logfile
fi
subor /home/etharendil/ipadresy
10.224.34.1 Gateway
x.146.142.x GatewayExternal
x.146.142.x SquidExternal
10.252.254.221 DNS01
10.252.254.220 DNS02
10.220.0.52 LWis-server
10.232.129.5 Postfix
10.224.34.6 Samba2-Wcko
10.224.34.9 Server
10.224.34.7 Palety
10.224.34.8 Spin
10.224.34.205 Backup
10.232.129.6 CDSpc
10.224.34.204 Phenon
10.224.34.39 TlackaLwisInland
10.224.34.40 TlackaLwisZberka
10.224.34.38 TlackaLwiszberka2
Viete niekto poradit cim to moze byt?
hmm moja sprostost... nenapisal som tam poriadne cestu k suboru ipadresy teda /home/etharendil/ipadresy....
keby sa niekomu nahodou hodilo taketo nieco tak prikladam opravene..
hmm.. místo nslookup bys měl používat raději dig
mno len problem je v tom, ze nslookup ani dig nemaju ziadne navratove hodnoty teda:
funkcne
# dig www.google.sk
; <<>> DiG 9.5.1-P1 <<>> www.google.sk
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 47892
;; flags: qr rd ra; QUERY: 1, ANSWER: 6, AUTHORITY: 7, ADDITIONAL: 0
.
;; AUTHORITY SECTION:
l.google.com. 79884 IN NS e.l.google.com.
.
.
# echo $?
0
nefunkcne
# dig sdfa
;; <<>> DiG 9.5.1-P1 <<>> sdfa
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 38970
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 0
; <<>> DiG 9.5.1-P1 <<>> sdfa
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 38970
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 0
.
.
# echo $?
0
a ked pouzijem dig tak neviem grepovat nic co by mi jednoznacne identifikovalo ze nic nenaslo ako u nslookup:
** server can't find www.google.: NXDOMAIN
resp. neviem ako to spravit :) Povodne som mal vacsie "monitorovacie" plany s nagiosom ale ked som kolko je to prace tak som to "odlozil" na neskor ))
ok:>>HEADER<<- opcode: QUERY, status: NOERROR, id: 47892
nefungující: >>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 38970
hmmmm dobre teda )) dakujem