Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Shellskriptprogrammierungsfrage

Empfohlene Antworten

Veröffentlicht

Hallo, hoffe ich bin hier richtig.

Sonst bitte ich nen Mod diesen Thread zu verschieben!

Ich möchte mir ein Shellskript schreiben das genau folgendes macht:

i=0

while [ $i -le 254 ]

do

i = `expr $i + 1`

ping -c 2 192.168.1.$i >> /log/pingstat.txt

done

Nun muss ich zugeben, dass ich von Shellprogrammierung keine Ahung habe, aber wenn ich das ausführe bekomme ich eine Endlosschleife mit der ausgabe:

./pingstat: i: command not found

ping: unknown host 192.168.20.

Die letzte Meldung ist logisch, die erste check ich nicht so wirklich, weil i ist doch eine Variable und kein Befehl.

Howtos kenn ich schon, aber wenn es sein ist wühl ich mich da noch tiefer rein.

Tschö und Gruß,

Containy


#!/bin/sh


HOST=1

MYNET=192.168.1

MYLOG=/var/log/pinglog


while [ ${HOST} -lt 255 ]

do

   ping -q -c 2 ${MYNET}.${HOST} >/dev/null 2>&1

   if [ $? -eq 0 ]

   then

     echo Host ${MYNET}.${HOST} reachable >> ${MYLOG}

   else

     echo Host ${MYNET}.${HOST} unreachable, error code $? >> ${MYLOG}

   fi

   let HOST=${HOST}+1

done

exit 0

./pingstat: i: command not found

Die letzte Meldung ist logisch, die erste check ich nicht so wirklich, weil i ist doch eine Variable und kein Befehl.

Dann hast du vermutlich zwischen i , = und dem wert leerzeichen gesetzt. Shell mag das nicht.

Falsch:


VARIABLE = WERT

Richtig:

VARIABLE=WERT

Ansonsten sollte deins auch gehen, aber ich habs mal frisiert mit Errorcode-Abfrage vom ping und dem let anstelle des expr.

  • Autor
Dann hast du vermutlich zwischen i , = und dem wert leerzeichen gesetzt. Shell mag das nicht.

Falsch:


VARIABLE = WERT

Richtig:

VARIABLE=WERT

Ansonsten sollte deins auch gehen, aber ich habs mal frisiert mit Errorcode-Abfrage vom ping und dem let anstelle des expr.

Joa das wars auch, ich hatte bei der zweiten Variableninitialisierung ein Leerzeichen drin. Danke.

Dein Script ist natürlich der Hammer. Hat mir aber gleich was beigebracht, nochmal danke.

Tschö,

Christian

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.