[Erledigt] Mit Script Datei fortlaufend nummeriert sichern ?

  • Hi,


    Ich hab hier ein Problem ne bestimmte Datei bei Bedarf fortlaufend nummeriert zu sichern.


    Beispiel:
    Ich hab ein Verzeichnis /home/trara
    In diesem kann eine Datei mit Namen hallo.conf liegen, muss aber nicht.
    Nun will ich aber in einem Script nen Befehl dazu haben falls eine hallo.conf
    in /home/trara liegt diese in hallo1.conf umbenannt wird, und falls ich das Script wieder mal ausführe, und es liegt wieder eine hallo.conf dort, aber auch schon ne hallo1.conf
    das dann die hallo.conf in hallo2.conf umbenannt wird usw. (also fortlaufend nummeriert)


    Ist das machbar?


    Hab ein bisschen mit dem nachstehenden Befehl gespielt


    cd /home/trara
    let a=1; for i in hallo*.conf; do let a=a+1; mv $i hallo$a.conf; done


    Das klappt aber nur einmal > die hallo.conf wird dann in hallo2.conf umbenannt.
    Führe ich den Befehl dann nochmal aus, klappts aber nicht mehr da dann schon eine
    hallo2.conf vorhanden ist.


    Es kommt dann die Meldung;
    mv: »hallo2.conf« und »hallo2.conf« sind die gleiche Datei.


    Ich aber will das hier keine Abfrage oder sonstiges kommt, sondern einfach ne
    hallo3.conf, beim nächsten mal ne hallo4.conf usw.usw.. erstellt wird.



    Gruss, Bert

    Hardware: Intel Core i9-9900K, ASUS ROG Maximus XI Hero, MSI GeForce GTX 1050 Ti (vdpau), Dvbsky S952 V3 mit 2X DVB-S2 Tuner
    Multibootsystem (yavdr-ansible auf Ubuntu-20.04, Kubuntu-20.04 Focal Fossa, Win10)
    yavdr-ansible, Ausgabe über Nvidia vdpau

    Einmal editiert, zuletzt von Bert ()

  • Hi,

    Code
    file="hallo.conf"; i=1; while [ -f "$(basename "$file" .conf)$i.conf" ]; do ((i++)); done; echo mv "$file" "$(basename "$file" .conf)$i.conf"


    Ganz primitiv, sucht den nächsten freien Namen, nur brauchbar wenn Du nicht tausende Dateien hast... ;)

    VDR1: Gigabyte GA-M720-US3 (nVidia Corporation MCP78S [GeForce 8200]), Athlon II X2 240, 2GB RAM, Intel 82574L Gigabit, Debian Squeeze, Kernel 2.6.38.3 mit linux-media.tar.bz2 vom 20.04. 10:04, dvbhddevice fb6b1beedb72, VDR-1.7.22 (extension-Patch, 15 Plugins), epgsearch, extrecmenu, ...
    VDR2: Debian Etch, 2.6.21.3, K6-2 400, 192MB, NFS-Root, 466GiB über NFS, 1xNexus 2.1, 1xNova S, VDR-1.4.7
    Server: Debian Squeeze, 2.6.35.7, AMD X2 240e, 4GB, System: Raid1 2x500GB, Aufnahmen: Raid5 4TB + 1x 500GB, 1000MBit LAN
    Episodenlisten für epgsearch, VDRSeriesTimer

  • Moin,



    cp --backup=numbered
    könnte helfen. "man cp" ist Dein Freund.


    Gruss,
    Walter

    --seit 2010 kein vdr mehr in Betrieb--
    vdr 1.6.0 + eigene Patchkombination
    GNU/Linux 2.6.23.14 (Debian)
    DVB-S-Karte TT 1.6 (FF, Tuner defekt)
    DVB-S-Karte TT Budget (seit 4/09)
    DVB-T-Karte TT 1300
    DVB-T-USB-StickTerratec Cinergy T USB XE Rev. 2
    PC-Hauptplatine: MSI K8N Neo4-F, AMD 64 (seit 1/07)

  • Hi, vejoun


    Thanks, aber irgendwie klappt das nicht.
    Hab das jetzt so in nem Script stehen;


    Code
    file="/home/trara/hallo.conf"; i=1;
    while [ -f "$(basename "$file" .conf)$i.conf" ];
    do
           ((i++)); done; echo mv "$file" "$(basename "$file" .conf)$i.conf"


    Führe ich das aus kommt zwar das in der Shell;


    mv /home/trara/hallo.conf hallo1.conf


    aber ich finde kein File hallo1.conf in /home/trara



    Gleiches passiert wenn ich nur deinen Befehl in der Shell wie folgt;


    Code
    file="hallo.conf"; i=1; while [ -f "$(basename "$file" .conf)$i.conf" ]; do ((i++)); done; echo mv "$file" "$(basename "$file" .conf)$i.conf"


    eingebe, wobei ich mich im Verzeichnis /home/trara befinde, und eine hallo.conf
    vorhanden ist.



    Gruss, Bert

    Hardware: Intel Core i9-9900K, ASUS ROG Maximus XI Hero, MSI GeForce GTX 1050 Ti (vdpau), Dvbsky S952 V3 mit 2X DVB-S2 Tuner
    Multibootsystem (yavdr-ansible auf Ubuntu-20.04, Kubuntu-20.04 Focal Fossa, Win10)
    yavdr-ansible, Ausgabe über Nvidia vdpau

    Einmal editiert, zuletzt von Bert ()

  • Hallo Bert,


    nimm mal das "echo" raus...


    ARK

    VDR
    ASUS A7N8X-X, AMD 2600+, 2 GB, 320 GB HD, Hauppauge DVB-S 1.3, Hauppauge Nova-S-Plus, Funktastatur
    Debian 4.0/Etch-Kernel 2.6.18-5-486
    c't-VDR 6.1 mit e-tobi 1.6.0 (neu gepatched ohne sortrecordings), acpi, vdradmin-am, burn, osdteletext, ffnetdev, audiorecorder, infosatepg, ...
    Client
    dbox2 (Sagem 2xI_C) mit Neutrino-Derivat

  • Hi, Walter, dg9ep


    Zitat

    cp --backup=numbered
    könnte helfen. "man cp" ist Dein Freund.


    Mann, so einfach kanns sein > du hast recht, das haut hin.


    Hab das total übersehen, hatte zuvor das;


    cp -r --suffix=_old /home/trara/hallo.conf /home/trara/use


    Thanks,


    Dennoch interessiert mich der Befehl von vejoun brennend, da ich nun mal anfangen möchte mich mit Scripting auseinanderzusetzen.



    Gruss, Bert

    Hardware: Intel Core i9-9900K, ASUS ROG Maximus XI Hero, MSI GeForce GTX 1050 Ti (vdpau), Dvbsky S952 V3 mit 2X DVB-S2 Tuner
    Multibootsystem (yavdr-ansible auf Ubuntu-20.04, Kubuntu-20.04 Focal Fossa, Win10)
    yavdr-ansible, Ausgabe über Nvidia vdpau

  • Das mit cp ist cool, war mir in all den Jahren nie bewußt aufgefallen. :)
    Und ark hat recht, das echo muss raus, hätte ich erwähnen sollen. Ich pack vor kritischen Befehlen wie mv, rm etc meist erst ein echo, dann kann niemand meckern wenn die Platte leer ist ;)
    Hier nochmal die langform, auch hier entferne dann das echo:

    Code
    file="hallo.conf"
    i=1
    while [ -f "$(basename "$file" .conf)$i.conf" ]; do
      ((i++))
    done
    echo mv "$file" "$(basename "$file" .conf)$i.conf"

    VDR1: Gigabyte GA-M720-US3 (nVidia Corporation MCP78S [GeForce 8200]), Athlon II X2 240, 2GB RAM, Intel 82574L Gigabit, Debian Squeeze, Kernel 2.6.38.3 mit linux-media.tar.bz2 vom 20.04. 10:04, dvbhddevice fb6b1beedb72, VDR-1.7.22 (extension-Patch, 15 Plugins), epgsearch, extrecmenu, ...
    VDR2: Debian Etch, 2.6.21.3, K6-2 400, 192MB, NFS-Root, 466GiB über NFS, 1xNexus 2.1, 1xNova S, VDR-1.4.7
    Server: Debian Squeeze, 2.6.35.7, AMD X2 240e, 4GB, System: Raid1 2x500GB, Aufnahmen: Raid5 4TB + 1x 500GB, 1000MBit LAN
    Episodenlisten für epgsearch, VDRSeriesTimer

  • Hi, ark


    Zitat

    nimm mal das "echo" raus...


    Ja, Danke > das funktioniert so


    Aber zumindest wenn ich nur den Befehl absetze und der Fall eintritt das dann doch keine hallo.conf dort liegen sollte klappts dann nicht mehr.


    Da kommt dann;
    mv: Aufruf von stat für »hallo.conf« nicht möglich: Datei oder Verzeichnis nicht gefunden


    Wie kann man das noch lösen ?


    Gruss, Bert

    Hardware: Intel Core i9-9900K, ASUS ROG Maximus XI Hero, MSI GeForce GTX 1050 Ti (vdpau), Dvbsky S952 V3 mit 2X DVB-S2 Tuner
    Multibootsystem (yavdr-ansible auf Ubuntu-20.04, Kubuntu-20.04 Focal Fossa, Win10)
    yavdr-ansible, Ausgabe über Nvidia vdpau

  • Hi, vejoun


    Danke, das klappt auch schon mal.


    Gruss, Bert

    Hardware: Intel Core i9-9900K, ASUS ROG Maximus XI Hero, MSI GeForce GTX 1050 Ti (vdpau), Dvbsky S952 V3 mit 2X DVB-S2 Tuner
    Multibootsystem (yavdr-ansible auf Ubuntu-20.04, Kubuntu-20.04 Focal Fossa, Win10)
    yavdr-ansible, Ausgabe über Nvidia vdpau

  • Das hab ich überlesen, setz in Zeile 2 dies rein, dann exitet es wenn die Datei nicht da ist:

    Code
    [ ! -f "$file" ] && { exit; }


    Das ist übrigens die Kurzform für

    Code
    if [ ! -f "$file" ]
    then
      exit 0
    fi


    ;)

    VDR1: Gigabyte GA-M720-US3 (nVidia Corporation MCP78S [GeForce 8200]), Athlon II X2 240, 2GB RAM, Intel 82574L Gigabit, Debian Squeeze, Kernel 2.6.38.3 mit linux-media.tar.bz2 vom 20.04. 10:04, dvbhddevice fb6b1beedb72, VDR-1.7.22 (extension-Patch, 15 Plugins), epgsearch, extrecmenu, ...
    VDR2: Debian Etch, 2.6.21.3, K6-2 400, 192MB, NFS-Root, 466GiB über NFS, 1xNexus 2.1, 1xNova S, VDR-1.4.7
    Server: Debian Squeeze, 2.6.35.7, AMD X2 240e, 4GB, System: Raid1 2x500GB, Aufnahmen: Raid5 4TB + 1x 500GB, 1000MBit LAN
    Episodenlisten für epgsearch, VDRSeriesTimer

  • Hi, vejoun


    Danke > jetzt hauts hin ! :]


    Hab die ganze Zeit versucht eine if Abfrage da noch reinzukriegen, hat aber nicht geklappt
    in Verbindung mit der While Schleife, da ich von der While Schleife noch kaum Ahnung hab.
    Bin halt noch ein Anfänger im Scripting.



    Gruss, Bert

    Hardware: Intel Core i9-9900K, ASUS ROG Maximus XI Hero, MSI GeForce GTX 1050 Ti (vdpau), Dvbsky S952 V3 mit 2X DVB-S2 Tuner
    Multibootsystem (yavdr-ansible auf Ubuntu-20.04, Kubuntu-20.04 Focal Fossa, Win10)
    yavdr-ansible, Ausgabe über Nvidia vdpau

    2 Mal editiert, zuletzt von Bert ()

  • Wenn es dir nicht auf das kontinuierliche Durchnummerieren ankommt, kann man auch einfach das aktuelle Datum und die Uhrzeit in die Kopie einarbeiten. Das spart das mühselige Suchen nach einer freien Nummer.


    Code
    date=`date +%Y%m%d%H%M%S`
    cp hallo.conf hallo-$date.conf


    Gruß,


    Udo

  • Hi, Udo


    Zitat

    Wenn es dir nicht auf das kontinuierliche Durchnummerieren ankommt, kann man auch einfach das aktuelle Datum und die Uhrzeit in die Kopie einarbeiten. Das spart das mühselige Suchen nach einer freien Nummer.


    Nein kommt mir nicht darauf an > Danke guter Tip !


    Gruss, Bert

    Hardware: Intel Core i9-9900K, ASUS ROG Maximus XI Hero, MSI GeForce GTX 1050 Ti (vdpau), Dvbsky S952 V3 mit 2X DVB-S2 Tuner
    Multibootsystem (yavdr-ansible auf Ubuntu-20.04, Kubuntu-20.04 Focal Fossa, Win10)
    yavdr-ansible, Ausgabe über Nvidia vdpau

  • DAS hättest Du auch gleich sagen können... :lehrer1 :lol2

    VDR1: Gigabyte GA-M720-US3 (nVidia Corporation MCP78S [GeForce 8200]), Athlon II X2 240, 2GB RAM, Intel 82574L Gigabit, Debian Squeeze, Kernel 2.6.38.3 mit linux-media.tar.bz2 vom 20.04. 10:04, dvbhddevice fb6b1beedb72, VDR-1.7.22 (extension-Patch, 15 Plugins), epgsearch, extrecmenu, ...
    VDR2: Debian Etch, 2.6.21.3, K6-2 400, 192MB, NFS-Root, 466GiB über NFS, 1xNexus 2.1, 1xNova S, VDR-1.4.7
    Server: Debian Squeeze, 2.6.35.7, AMD X2 240e, 4GB, System: Raid1 2x500GB, Aufnahmen: Raid5 4TB + 1x 500GB, 1000MBit LAN
    Episodenlisten für epgsearch, VDRSeriesTimer

  • Hi, vejoun


    Zitat

    DAS hättest Du auch gleich sagen können...


    Da hast du natürlich recht ;)


    Aber es schadet ja auch nix mehrere Varianten zu kennen.



    Gruss, Bert

    Hardware: Intel Core i9-9900K, ASUS ROG Maximus XI Hero, MSI GeForce GTX 1050 Ti (vdpau), Dvbsky S952 V3 mit 2X DVB-S2 Tuner
    Multibootsystem (yavdr-ansible auf Ubuntu-20.04, Kubuntu-20.04 Focal Fossa, Win10)
    yavdr-ansible, Ausgabe über Nvidia vdpau

    Einmal editiert, zuletzt von Bert ()

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!