Wo ist der Fehler im Skript?

Post Reply
Message
Author
...___...___...

Wo ist der Fehler im Skript?

#1 Post by ...___...___... »

Warum funzt das nicht? <img src="http://www.pl-forum.de/UltraBoard/Images/Sad.gif" border="0" align="middle">
<blockquote><pre><font size="1" face="">code:</font><hr><font face="Courier New" size="2">
#!/bin/sh
#
DATUM=`date +%d-%m-%Y`
VERZEICHNIS1=mnt/camera/cam-1/
#VERZEICHNIS2=mnt/camera/cam-2/
#VERZEICHNIS3=mnt/camera/cam-3/
ARCHIV1=$VERZEICHNIS1/archiv/
#ARCHIV2=$VERZEICHNIS2/archiv/
#ARCHIV3=$VERZEICHNIS3/archiv/
#
cd /
#
mount -t smbfs -o username=xxx,password=yyy //10.104.10.202/camera$ /mnt/camera
#
find $VERZEICHNIS1 -ctime -1 -print -exec tar cvfs $ARCHIV1/images_$DATUM.tar {} \ ;
#
#tar cvzf $DATUM.tar.gz
#
umount /mnt/camera
#
exit 0
</font><hr></pre></blockquote>
Fehlermeldung:
fserver1:/batch # ./compress_cams.sh
INFO: Debug class all level = 3 (pid 21123 from pid 21123)
opts: rw
opts: username=xxx
opts: password=yyy
mount.smbfs started (version 2.2.5)
added interface ip=10.104.10.210 bcast=10.104.10.255 nmask=255.255.255.0
Connecting to 10.104.10.202 at port 139
21123: session request to 10.104.10.202 failed (Called name not present)
Connecting to 10.104.10.202 at port 139
21123: session request to 10 failed (Called name not present)
Connecting to 10.104.10.202 at port 139
find: missing argument to `-exec'

Wie muß der Aufruf denn aussehen?

User avatar
hjb
Pro-Linux
Posts: 3264
Joined: 15. Aug 1999 16:59
Location: Bruchsal
Contact:

Re: Wo ist der Fehler im Skript?

#2 Post by hjb »

Hi,

du hast ein Leerzeichen zwischen \ und ;
Das muß weg.

Gruß,
hjb
Pro-Linux - warum durch Fenster steigen, wenn es eine Tür gibt?

...___...___...

Re: Wo ist der Fehler im Skript?

#3 Post by ...___...___... »

Danke!
Nun läuft es.
man find sagt u. a.:
<i>das Semikolon kann nicht weggelassen werden, und es muß durch mindestens ein Whitespace von der letzen Option getrennt werden;</i>
Darum halt der Leerschritt.

Man lernt ja nicht aus ...

...___...___...

Re: Wo ist der Fehler im Skript?

#4 Post by ...___...___... »

Kann da eigentlich dann noch etwas angefügt werden?
Etwa in der Art:
<blockquote><pre><font size="1" face="">code:</font><hr><font face="Courier New" size="2">find $VERZEICHNIS1 -ctime -1 -print -exec tar cvfs $ARCHIV1/images_$DATUM.tar {} <i>-exec rm {}</i> ;<!--no--></font><hr></pre></blockquote>

Danke.

...___...___...

Re: Wo ist der Fehler im Skript?

#5 Post by ...___...___... »

Sollte:
<blockquote><pre><font size="1" face="">code:</font><hr><font face="Courier New" size="2">find $VERZEICHNIS1 -ctime -1 -print -exec tar cvfs $ARCHIV1/images_$DATUM.tar {} -exec rm {} ;<!--no--></font><hr></pre></blockquote>
heißen.

...___...___...

Re: Wo ist der Fehler im Skript?

#6 Post by ...___...___... »

Sollte:
<blockquote><pre><font size="1" face="">code:</font><hr><font face="Courier New" size="2">find $VERZEICHNIS1 -ctime -1 -print -exec tar cvfs $ARCHIV1/images_$DATUM.tar {} -exec rm {} ;<!--no--></font><hr></pre></blockquote>
heißen.

...___...___...

Re: Wo ist der Fehler im Skript?

#7 Post by ...___...___... »

Warum verschluckt er denn nun den Backslash am Ende der Zeile?

Jochen

Re: Wo ist der Fehler im Skript?

#8 Post by Jochen »

Alles eine Sache des Quotings. Den Backslash verschluckt das Board, da es ihn selbst interpretiert. Das wird benötigt, wenn man z.B. [<!--no-->code]...[<!--no-->/code] schreiben will, ohne dass es <blockquote><pre><font size="1" face="">code:</font><hr><font face="Courier New" size="2">dann so aussieht.</font><hr></pre></blockquote>

Und das gleiche Problem gilt für find und die Shell. Das Semikolon würde das find-Kommando für die Shell beenden. Wenn man aber noch weitere -execs an den find bauen will, muss find ja auch irgendwie das Ende des ersten -exec-Arguments erkennen. Daher muss man mittels ";" als letztes einzelnes Zeichen anzeigen, dass das Komamndo zu -exec zu Ende ist. Damit die Shell nun hier nicht das ganze find-Kommando beendet, muss man es entwerten, also einen Backslash davorsetzen. Mehrere -execs zu einem find macht ma also so:<pre>find . -name datei -exec echo "Habe datei" \<!--no-->; -exec echo "gefunden" \<!--no-->;</pre>Bei der Eingabe für's Board muss man dann natürlich \<!--no-->\<!--no-->; statt \<!--no-->; tippen, sonst erhält man nur ;. <img src="http://www.pl-forum.de/UltraBoard/Images/Happy.gif" border="0" align="middle">

Jochen

...___...___...

Re: Wo ist der Fehler im Skript?

#9 Post by ...___...___... »

Ah .... !!!

Danke schön!

...___...___...

Re: Wo ist der Fehler im Skript?

#10 Post by ...___...___... »

Also muß es dann so aussehen:
<blockquote><pre><font size="1" face="">code:</font><hr><font face="Courier New" size="2">
find $VERZEICHNIS1 -ctime -1 -print -exec tar cvfs $ARCHIV1/images_$DATUM.tar {}; -exec rm {} \<!--no-->;
</font><hr></pre></blockquote>

Korrekt?

Jochen

Re: Wo ist der Fehler im Skript?

#11 Post by Jochen »

Öhm - nö? <img src="http://www.pl-forum.de/UltraBoard/Images/Happy.gif" border="0" align="middle">

Von der Syntax her sollte es so aussehen:<pre>find $VERZEICHNIS1 -ctime -1 -print -exec tar cvfs $ARCHIV1/images_$DATUM.tar {} \<!--no-->; -exec rm {} \<!--no-->;</pre>Nur habe ich das dumpfe Gefühl, dass dieses Kommando nicht macht, was Du willst... Die Archiv-Datei wird wegen der Option -c (create) für jede neu gefundene Datei <b>neu angelegt</b> und der alte Inhalt damit überschrieben. Verwende statt dessen lieber die Option "-r" bzw. "--append":<blockquote><pre><font size="1" face="">code:</font><hr><font face="Courier New" size="2">find $VERZEICHNIS1 -ctime -1 -print -exec tar <b>r</b>vfs $ARCHIV1/images_$DATUM.tar {} \<!--no-->; -exec rm {} \<!--no-->;
</font><hr></pre></blockquote>Tipp am Rande: Solange Du solche Skripte testet, setze vor alle gefährlichen Kommandos wie rm ein echo. So kannst Du sehen, was das Skript gerne tun würde, ohne dass die Dateien direkt verschwinden...

Jochen

Post Reply