Crontab Ausgabe in täglich neue Datei mit Datum im Namen

  • Hallo allerseits,
    Ich habe mal noch eine Frage zu crontab/jobs:

    Ich habe ein Script über die crontab laufen welches fortwähren die Temperatur eines Sensors in eine log-Datei schreibt. Ich möcht natürlich jeden Tag eine neue (mit Datum) haben.
    Nach dem Schema %Y-%m-%d.log funktioniert es bei mir nicht. wenn ich einen normalen Dateinamen (temp.log) einstelle, funktioniert es korrekt.

    Hier meine crontab Versionen die ich bis jetzt probiert habe: (manuell im Terminal funktioniert die Datumsvariable)

    */5 * * * * /home/pi/scripte/mrtg/update_mrtg_temp.sh >> /home/pi/Temp-%Y-%m-%d.log

    Code
    */5 * * * * /home/pi/scripte/mrtg/update_mrtg_temp.sh >>/home/pi/Temp-`date '+%Y-%m-%d'`.log
    Code
    */5 * * * * /home/pi/scripte/mrtg/update_mrtg_temp.sh >> /home/pi/Temp-$(date +%Y-%m-%d).log



    Hier mein Script:

    #!/bin/bash

    # Read temperature from sensor
    tempread=`cat /sys/devices/w1_bus_master1/10-000802b57b2c/w1_slave`

    temp=`echo $tempread | egrep -o '.{5}$'`

    temp2=`echo "scale=2; $temp / 1000" | bc`

    # Update database
    echo $temp2
    echo 0
    echo 0
    echo temperature

    -----------------------------------------------------------------------------

    Was läuft falsch ?

    Das Script war ursprünglich für MRTG gedacht. Da ich aber nach langem Gefummel nicht hinbekommen habe das die Temperaturgraphen in MRTG dargestellt werden, nutze ich das Script nun auf diese Weise.
    Auswertung erfolgt ganz traditionell mit Excel ... Ohne die letzten 5 Zeilen läuft das Script nicht (gibt keine Temperaturwerte aus)

    Gruß
    crepp

  • Crontab Ausgabe in täglich neue Datei mit Datum im Namen? Schau mal ob du hier fündig wirst!

  • Du hattest >hier< auch Fehlermeldungen gepostet wo sich mir aber nicht erschliest woher die kommen...

    Insbesondere: /bin/sh: 1: Syntax error: end of file unexpected (expecting ")")

    Wie kommt der auf "/bin/sh" obwohl im Script doch als Shebang /bin/bash steht?

    Gib mal bitte crontab -l ein und poste die Ausgabe in Kode

  • Die Ausgabe von crontab -l ergibt:

    cpi@raspberrypi ~ $ crontab -l
    # Edit this file to introduce tasks to be run by cron.
    #
    # Each task to run has to be defined through a single line
    # indicating with different fields when the task will be run
    # and what command to run for the task
    #
    # To define the time you can provide concrete values for
    # minute (m), hour (h), day of month (dom), month (mon),
    # and day of week (dow) or use '*' in these fields (for 'any').#
    # Notice that tasks will be started based on the cron's system
    # daemon's notion of time and timezones.
    #
    # Output of the crontab jobs (including errors) is sent through
    # email to the user the crontab file belongs to (unless redirected).
    #
    # For example, you can run a backup of all your user accounts
    # at 5 a.m every week with:
    # 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
    #
    # For more information see the manual pages of crontab(5) and cron(8)
    #
    # m h dom mon dow command

    #*/5 * * * * /home/pi/scripte/mrtg/update_mrtg_temp.sh >> /home/pi/temp.log
    */5 * * * * /home/pi/scripte/temp.sh >> /home/pi/temp_5min.log
    0 * * * * /bin/ls >/dev/null 2&>1 #Mailoutput crontab loeschen

    Hallo,

    Hab eben nochmal die syntax v. user0 getestet und damit funktioniert es !
    Das Thema ist also erledigt u. der Thread kann geschlossen werden.
    Vielen Dank für eure Hilfe

    Gruß
    crepp

    :bravo2:
    :bravo2:
    :thumbs1:

    Einmal editiert, zuletzt von crepp (20. November 2013 um 20:15)

Jetzt mitmachen!

Du hast noch kein Benutzerkonto auf unserer Seite? Registriere dich kostenlos und nimm an unserer Community teil!