Ping-Tool

niLs

niLs

òle òle
hallöchen,

ich bin gerade dabei, ein kleines ping-script zu schreiben, was mit den normalen linux-ping absetzt, aber im prinzip vor jede zeile die zeit der ausführung zu schreiben.

da crontab wohl nur minütliche ausführung zulässt, bin ich mit folgender idee nicht weitergekommen:

Code:
#!/bin/bash
#
# pingtest

#hier änderungen machen
pinghost="www.google.de"
logfile="/home/niLs/pingtest.log"


#hier nichts mehr ändern
pingzeit=`date +%A" "%d.%m.%Y" "%H:%M:%S`
pingopts=`ping -W3 -c1 $pinghost |grep 64`
falsemsg="Ziel ($pinghost) nicht erreichbar"
pingtrue="$pingzeit --- $pingopts"
pingfalse="$pingzeit --- $falsemsg"


if [ "$pingopts" == "" ]; then
   echo $pingfalse
else
   echo $pingtrue
fi

exit 0

eventuell hat ja noch jemand einen anderen ansatz :-)
 
ups, *lach*

also, ich möchte prinzipiell das ganze ohne -c1 ausführen, sodass er durchgängig pingt, mir aber immer schön die uhrzeit dazuschreibt. :)

gruß nils
 
Code:
pinghost="www.google.de"
logfile="/home/niLs/pingtest.log"


pingzeit=`date +%A" "%d.%m.%Y" "%H:%M:%S`
pingopts=`ping -W3 -c1 $pinghost |grep 64`
falsemsg="Ziel ($pinghost) nicht erreichbar"
pingtrue="$pingzeit --- $pingopts"
pingfalse="$pingzeit --- $falsemsg"

while :; do
if [ "$pingopts" == "" ]; then
   echo $pingfalse >> "$logfile"
else
   echo $pingtrue >> "$logfile"
fi
sleep 1;
done
 
Hallo smg,

danke schonmal für deine Hilfe, leider funktionierte das so nicht, die idee hatte ich auch schon.

Folgende Logfile-Einträge sehe ich dann:

Freitag 17.08.2007 08:38:27 --- 64 bytes from ug-in-f99.google.com (66.249.93.99): icmp_seq=1 ttl=248 time=17.0 ms
Freitag 17.08.2007 08:38:27 --- 64 bytes from ug-in-f99.google.com (66.249.93.99): icmp_seq=1 ttl=248 time=17.0 ms
Freitag 17.08.2007 08:38:27 --- 64 bytes from ug-in-f99.google.com (66.249.93.99): icmp_seq=1 ttl=248 time=17.0 ms
Freitag 17.08.2007 08:38:27 --- 64 bytes from ug-in-f99.google.com (66.249.93.99): icmp_seq=1 ttl=248 time=17.0 ms
Freitag 17.08.2007 08:38:27 --- 64 bytes from ug-in-f99.google.com (66.249.93.99): icmp_seq=1 ttl=248 time=17.0 ms
Freitag 17.08.2007 08:38:27 --- 64 bytes from ug-in-f99.google.com (66.249.93.99): icmp_seq=1 ttl=248 time=17.0 ms
Freitag 17.08.2007 08:38:27 --- 64 bytes from ug-in-f99.google.com (66.249.93.99): icmp_seq=1 ttl=248 time=17.0 ms
Freitag 17.08.2007 08:38:27 --- 64 bytes from ug-in-f99.google.com (66.249.93.99): icmp_seq=1 ttl=248 time=17.0 ms
Freitag 17.08.2007 08:38:27 --- 64 bytes from ug-in-f99.google.com (66.249.93.99): icmp_seq=1 ttl=248 time=17.0 ms
Freitag 17.08.2007 08:38:27 --- 64 bytes from ug-in-f99.google.com (66.249.93.99): icmp_seq=1 ttl=248 time=17.0 ms
Freitag 17.08.2007 08:38:27 --- 64 bytes from ug-in-f99.google.com (66.249.93.99): icmp_seq=1 ttl=248 time=17.0 ms
Freitag 17.08.2007 08:38:27 --- 64 bytes from ug-in-f99.google.com (66.249.93.99): icmp_seq=1 ttl=248 time=17.0 ms
Freitag 17.08.2007 08:38:27 --- 64 bytes from ug-in-f99.google.com (66.249.93.99): icmp_seq=1 ttl=248 time=17.0 ms
Freitag 17.08.2007 08:38:27 --- 64 bytes from ug-in-f99.google.com (66.249.93.99): icmp_seq=1 ttl=248 time=17.0 ms
Freitag 17.08.2007 08:38:27 --- 64 bytes from ug-in-f99.google.com (66.249.93.99): icmp_seq=1 ttl=248 time=17.0 ms
Freitag 17.08.2007 08:38:27 --- 64 bytes from ug-in-f99.google.com (66.249.93.99): icmp_seq=1 ttl=248 time=17.0 ms


Wie man sieht, läuft die Zeit nicht mit.

Gruß Nils
 
Wie auch, die Zeit wird ja nur einmal am Anfang instanziiert. Genau so verhält sich das mit dem Ping. So schreibt er dir die ganze Zeit immer die selbe Zeile ins Log.
Daher muss das alles für jeden Schleifendurchlauf neu angestoßen werden.

Quick'n'Dirty:

Code:
#!/bin/bash

pinghost="www.google.de"
logfile="/home/niLs/pingtest.log"

function pingtime() {
  pingzeit=`date +%A" "%d.%m.%Y" "%H:%M:%S`
  pingopts=`ping -W3 -c1 $pinghost |grep 64`
  falsemsg="Ziel ($pinghost) nicht erreichbar"
  pingtrue="$pingzeit --- $pingopts"
  pingfalse="$pingzeit --- $falsemsg"
}

while :; do
pingtime
if [ "$pingopts" == "" ]; then
   echo $pingfalse >> "$logfile"
else
   echo $pingtrue >> "$logfile"
fi
sleep 1;
done
 

Ähnliche Themen

NAS-Drive Mount in Bash-Script über crontab

Queue für copy Script

Prozess aus eigenem Init script wird gekillt

Script "gegenlesen"

SEM (Search Engine's reMastered)

Zurück
Oben