
Kann mir jemand helfen, dieses einfache Skript zu debuggen? Ich versuche es jetzt schon seit 2 Stunden, aber es funktioniert einfach nicht.
#!/bin/bash
echo "Search for MMSC or WAP connectivity errors"
sftpErrorCount=$(tail -100 3_ERRORs_log.txt | grep "MMSC_Upload2" | grep "Fail to copy"| awk '{print $1 " " $2" " $3" " $4}'| wc -l)
if [ "$sftpErrorCount" -gt 0 ]
then
sftpErrorDate=$(tail -100 3_ERRORs_log.txt | grep "MMSC_Upload2" | grep "Fail to copy"| awk '{print $1 " " $2" " $3" " $4}'| tail -1)
echo "Error found at around $sftpErrorDate please check FTP logs"
else
echo "No errors found"
Fehler beim Ausführen des Skripts:
$ sh test_script.sh
Search for MMSC or WAP connectivity errors
test_script.sh: line 14: syntax error: unexpected end of file
Antwort1
Sie müssen Ihre if-Anweisung mit dem Wort abschließen fi
.
#!/bin/bash
echo "Search for MMSC or WAP connectivity errors"
sftpErrorCount=$(tail -100 3_ERRORs_log.txt | grep "MMSC_Upload2" |
grep "Fail to copy"| awk '{print $1 " " $2" " $3" " $4}'| wc -l)
if [ "$sftpErrorCount" -gt 0 ] ; then
sftpErrorDate=$(tail -100 3_ERRORs_log.txt | grep "MMSC_Upload2" |
grep "Fail to copy"| awk '{print $1 " " $2" " $3" " $4}'| tail -1)
echo "Error found at around $sftpErrorDate please check FTP logs"
else
echo "No errors found"
fi
# ^ This closes the block.
Beachten Sie auch, dass ich einige Stiländerungen an Ihrem Skript vorgenommen habe. Einrückungen können das Auffinden solcher Fehler erleichtern.