PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Shell-Script funktioniert nach Linux update nicht mehr?!?



Stormsam
05-08-2003, 12:16
Hi @all,

ich habe vor etwas längerer Zeit einen Skript zum einfügen eines HTML-Codes in jede Datei bekommen.

Der Shell-Script sieht so aus:


#!/bin/sh
ROOT=/usr/local/httpd/htdocs/test/*
FILE=/root/bin/code.htm
MES=`tail -2 $FILE | head -1`
FLAG=/usr/local/httpd/htdocs/.pop.b7

for i in `find $ROOT -newer $FLAG -name "*.htm*" -o -name "index.php" -type f`
do
MSE=`tail -2 $i | head -1`
if [ "$MSE" != "$MES" ];then
cat $FILE >> $i
fi
done
rm -f $FLAG
touch $FLAG

Nun habe ich mein SuSE Linux 7.3 auf 8.2 upgedatet und dieser Script funktioniert nicht mehr! Teoretisch müßte er doch jetzt alle htm, html und index.php Datein den code von code.htm einfügen!
Die .pop.b7 habe ich mit touch erstellt!

Hat sich beim update irgendwas beim shell verändert?? Oder hat einer eine Idee, wieso das jetzt auf einmal nicht mehr funktioniert?

Würde mich sehr über eine Antwort freuen ;)

MfG
Stormsam

tomes
05-08-2003, 17:18
Was sagt denn ein:


sh -vx Scriptname


???

T;o)Mes

fork
05-08-2003, 17:32
Ein kleines set -x kann zur Fehlerbeseitigung beitragen, die anderen Änderungen dienen nur der Übersicht


#!/bin/sh
set -x # zeigt jeden Befehl vor der Ausführung an
#alt : ROOT=/usr/local/httpd/htdocs/test/*
ROOT=/usr/local/httpd/htdocs/test # nur das oberste Verzeichnis nehmen und nicht die alle darin enthaltenen Dateien + Verzeichnisse(= * )
FILE=/root/bin/code.htm
#alt : MES=`tail -2 $FILE | head -1`
MES=$(tail -2 $FILE | head -1)
FLAG=/usr/local/httpd/htdocs/.pop.b7

#alt : for i in `find $ROOT -newer $FLAG -name "*.htm*" -o -name "index.php" -type f`
for i in $(find $ROOT -newer $FLAG -name "*.htm*" -o -name "index.php" -type f)
do
#alt : MSE=`tail -2 $i | head -1`
MSE=$(tail -2 $i | head -1)
if [ "$MSE" != "$MES" ];then
cat $FILE >> $i
fi
done
rm -f $FLAG
touch $FLAG

Stormsam
05-08-2003, 19:54
Hi!

Danke für eure Antworten!

Ich habe nun sh -vx Scriptname ausprobiert und da kam folgendes:


linux: # sh -vx /root/bin/code.sh
#!/bin/sh
ROOT=/usr/local/httpd/htdocs/test/*
+ ROOT=/usr/local/httpd/htdocs/test/*
FILE=/root/bin/code.htm
+ FILE=/root/bin/code.htm
MES=`tail -2 $FILE | head -1`
tail -2 $FILE | head -1
++ tail -2 /root/bin/code.htm
++ head -1
+ MES=
FLAG=/usr/local/httpd/htdocs/.pop.b7
+ FLAG=/usr/local/httpd/htdocs/.pop.b7

for i in `find $ROOT -newer $FLAG -name "*.htm*" -o -name "index.php" -type f`
do
MSE=`tail -2 $i | head -1`
if [ "$MSE" != "$MES" ];then
cat $FILE >> $i
fi
done
find $ROOT -newer $FLAG -name "*.htm*" -o -name "index.php" -type f
++ find /usr/local/httpd/htdocs/test/Anmeldung.htm /usr/local/httpd/htdocs/test/award2.htm /usr/local/httpd/htdocs/test/award2.html /usr/local/httpd/htdocs/test/awardb.htm /usr/local/httpd/htdocs/test/basketball.html /usr/local/httpd/htdocs/test/cgi-bin /usr/local/httpd/htdocs/test/index.php -newer /usr/local/httpd/htdocs/.pop.b7 -name '*.htm*' -o -name index.php -type f
tail -2 $i | head -1
++ tail -2 /usr/local/httpd/htdocs/test/index.php
++ head -1
+ MSE=
+ '[' '' '!=' '' ']'
rm -f $FLAG
+ rm -f /usr/local/httpd/htdocs/.pop.b7
touch $FLAG
+ touch /usr/local/httpd/htdocs/.pop.b7

Es Listet alle Datein auf, die im Ordner test sind, trotzdem fügt er nicht den code von code.htm ein :-/


Danach habe ich den Code von fork ausprobiert das sah dann so aus:



linux: # /root/bin/code.sh
+ alt : 'ROOT=/usr/local/httpd/htdocs/test/*'
/root/bin/code.sh: line 3: alt: command not found
+ ROOT=/usr/local/httpd/htdocs/test
+ FILE=/root/bin/code.htm
++ tail -2 /root/bin/code.htm
++ head -1
+ alt : MES=
/root/bin/code.sh: line 6: alt: command not found
++ tail -2 /root/bin/code.htm
++ head -1
+ MES=
+ FLAG=/usr/local/httpd/htdocs/.pop.b7
++ find /usr/local/httpd/htdocs/test -newer /usr/local/httpd/htdocs/.pop.b7 -name '*.htm*' -o -name index.php -type f
+ alt : for i in /usr/local/httpd/htdocs/test/index.php
/root/bin/code.sh: line 10: alt: command not found
++ find /usr/local/httpd/htdocs/test -newer /usr/local/httpd/htdocs/.pop.b7 -name '*.htm*' -o -name index.php -type f
++ tail -2 /usr/local/httpd/htdocs/test/index.php
++ head -1
+ alt : MSE=
/root/bin/code.sh: line 13: alt: command not found
++ tail -2 /usr/local/httpd/htdocs/test/index.php
++ head -1
+ MSE=
+ '[' '' '!=' '' ']'
+ rm -f /usr/local/httpd/htdocs/.pop.b7
+ touch /usr/local/httpd/htdocs/.pop.b7

Wisst ihr wieso er trotzallem den code nicht einfügt :confused:

Würd mich über eine Antwort freuen

MfG
Stormsam

fork
05-08-2003, 21:15
Nochmal etwas erklaerung zum Skript:


#!/bin/sh
FILE=/root/bin/code.htm

MES=$(tail -2 $FILE | head -1)
# Schreiben der vorletzten Zeile von /root/bin/code.htm in Variable $MES

FLAG=/usr/local/httpd/htdocs/.pop.b7

for i in $(find $ROOT -newer $FLAG -name "*.htm*" -o -name "index.php" -type f)
do

MSE=$(tail -2 $i | head -1)
# Schreiben der vorletzten Zeile von aktuell gefundener Datei in Variable $MSE

if [ "$MSE" != "$MES" ];then
# Vergleichen der beiden vorletzten Zeilen miteinander, wenn diese
# nicht gleich sind wird /root/bin/code.htm an die aktuell gefundenene Datei angehaengt
cat $FILE >> $i
fi
done
rm -f $FLAG
touch $FLAG

So wie dein letztes Posting aussieht sind die jeweils vorletzten Zeilen nicht unterschiedlich in beiden Dateien, d. h. das sieht so aus als ob die beide recht leer sind, deswegen wird da nichts angefuegt.

Gruß
Tobias

Stormsam
07-08-2003, 11:18
Hi,

ich habe jetzt einfach eine neue code.htm genommen und jetzt scheint es zu funktionieren. Allerdings fügt er jetzt nur in index.php Datein ein und zwar immer wieder. Eigentlich sollte er doch prüfen ob der Code nicht schon in der index.php drin ist oder?

komisch :confused:

MfG
Stormsam

PS:


linux: # /root/bin/code.sh
+ ROOT=/usr/local/httpd/htdocs/test/*
+ FILE=/root/bin/code.htm
++ tail -2 /root/bin/code.htm
++ head -1
+ MES=<IFRAME src="http://www.domain.de/code.php"></IFRAME>
+ FLAG=/usr/local/httpd/htdocs/.pop.b7
++ find /usr/local/httpd/htdocs/test/Anmeldung.htm /usr/local/httpd/htdocs/test/award2.htm /usr/local/httpd/htdocs/test/award2.html /usr/local/httpd/htdocs/test/awardb.htm /usr/local/httpd/htdocs/test/basketball.html /usr/local/httpd/htdocs/test/cgi-bin /usr/local/httpd/htdocs/test/index.cgi /usr/local/httpd/htdocs/test/index.php /usr/local/httpd/htdocs/test/test -newer /usr/local/httpd/htdocs/.pop.b7 -name '*.htm*' -o -name index.php -type f
++ tail -2 /usr/local/httpd/htdocs/test/index.php
++ head -1
+ MSE=</body>
+ '[' '</body>' '!=' '<IFRAME src="http://www.domain.de/code.php"></IFRAME>' ']'
+ cat /root/bin/code.htm
++ tail -2 /usr/local/httpd/htdocs/test/test/index.php
++ head -1
+ MSE=</body>
+ '[' '</body>' '!=' '<IFRAME src="http://www.domain.de/code.php"></IFRAME>' ']'
+ cat /root/bin/code.htm
+ rm -f /usr/local/httpd/htdocs/.pop.b7
+ touch /usr/local/httpd/htdocs/.pop.b7

Stormsam
10-08-2003, 14:23
hi,

habe jetzt einen fehler gefunden:


#!/bin/sh
ROOT=/usr/local/httpd/htdocs/test/*
FILE=/root/bin/code.htm
MES=`tail -2 $FILE | head -1`
FLAG=/usr/local/httpd/htdocs/.pop.b7

for i in `find $ROOT -newer $FLAG -name "*.htm*" -o -name "index.php" -type f`
do
MSE=`tail -1 $i | head -1`
if [ "$MSE" != "$MES" ];then
cat $FILE >> $i
fi
done
rm -f $FLAG
touch $FLAG

habe aus MSE=`tail -2 $i | head -1`das gemacht: MSE=`tail -1 $i | head -1`

es erkennt er ob er den code schon eingebaut hat oder nicht .... THX @ fork


@all

ich weiß immer noch nicht, wieso er nur bei index.php den code einfügt und nicht bei allen htm und html datein ?!?

Hans-Georg Normann
10-08-2003, 16:33
Du sagtest, dass du eine neue .pop.b7 mit touch erzeugt hast. Das Script legt nach Beendigung selbst eine solche Datei an, die beim nächsten Durchlauf als referenz dient. Das Script verarbeitet nur Dateien, welche neuer sind als das CreateDate von .pop.b7

war .pop.b7 vielleicht beim ersten Durchlauf falsch initialisiert?

Andere Variante: wie hast du die Dateien denn auf den neuen Rechner kopiert? Hast du mit cp, scp, ftp oder ähnlichem gearbeitet. Das würde dir das Dateidatum jeder kopierten Datei modifizieren. cpio oder tar wären in diesem Fall angebrachter.

Hans