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.

Empfohlene Antworten

Veröffentlicht

Hi allerseits,

ich habe ein paar Dinge, die ich per Shell Script lösen soll. Zunächst folgendes:

Ich erzeuge per Skript eine Datei, in die z.B. reingeschrieben wird "nicht verfügbar", aber auch anderes. Ich will nun diese Datei (return.log heißt se) nach diesem Striing "nicht verfügbar" durchsuchen. Wird ein solcher String gefunden, das kann auch mehrmals sein, sollen alle entsprechenden Zeilen in eine Datei return$timestamp.log geschrieben werden. Das mit dem Timestamp und das Anlegen der Datei krieg ich hin. Ich weiß nur nicht genau wie ich nur die der Suche entsprechenden Zeilen da rein kriege (sicher irgendwie mit >> oder >). Und das suchen geht bestimmt mit grep, aber wie genau?

Weiterhin soll, wenn der String "nicht verfügbar" NICHT gefunden wurde, in eine neue Datei (z.B. returnrc.log) der aktuelle Timestamp und der Satz "alle Systeme verfügbar" geschrieben werden.

Könnt ihr mir dabei helfen?

Wäre echt super!

Danke schonmal!

okay, das mit dem Suchen des Strings hab ich auch schon:

OUTPUT_DIR="/archive/lib/icmadmin";

OUTPUT_FILE="return.log";

location=wlp1prod

user=wlpftp

pw=wlpftp

db2 -a +o connect to $location user $user using $pw

b="$?"

if [ "$b" = 0 ]; then

print "$location verfügbar" >> $OUTPUT_FILE

elif [ "$b" > 0 ]; then

print "$location nicht verfügbar" >> $OUTPUT_FILE

fi

timestamp=$(date '+%Y%m%d-%H:%M:%S')

errors=$(grep "nicht verfügbar" return.log | wc -l)

echo $errors

cp return.log return$timestamp.log

so und jetzt fehlt jetzt quasi, if $errors > 0, then schreibe die Zeilen mit "nicht verfügbar" in Datei return$timestamp.log

Aktualisierung:

inzwischen klappen nur 2 Dinge noch nicht:

die Ausgabe des grep von errors2 ins Nichts umleiten

irgendwas mit der Definition von $ERROR_FILE

der Rest des Skripts ist hier unwichtig:

timestamp=$(date '+%Y%m%d-%H:%M:%S')

touch return$timestamp.log

$ERROR_FILE=return$timestamp.log

errors=$(grep "nicht verfügbar" return.log | wc -l)

errors2=`grep "nicht" return.log >nul`

###echo $errors2

echo $errors

if [ "$errors" > 0 ]; then

print "$errors2" >> $ERROR_FILE

elif [ "$errors" = 0 ]; then

print "$timestamp : Alle Systeme verfügbar" >> $OUTPUT_FILE2

fi

Dein Error-Problem: Zeile 3 das $ am Anfang muss weg vor ERROR_FILE.

Ins "Nichts" umleiten:

Eigentlich sollte die Zeile so gar keinen Output erzeugen: errors2=`grep "nicht" return.log`

Wenn du sichergehen möchtest leite es nach /dev/null um. Also:

errors2=`grep "nicht" return.log > /dev/null`

Gruß

Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.

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.