View previous topic :: View next topic |
Author |
Message |
andreas2000 Tux's lil' helper


Joined: 02 Nov 2004 Posts: 144 Location: Austria/Vienna
|
Posted: Thu Jan 13, 2005 3:52 pm Post subject: SOLVED - Umleitung STDOUT in eindeutigen Filenamen? |
|
|
Hallo zusammen,
ich sitze hier schon wieder 2 Tage an einer Sache und komme nicht weiter - vielleicht hats aber schon wer von Euch realisiert...
Ich habe einen Cron Job gemacht, den ich dazu bewegen will eindeutige Logfiles zu schreiben.
Der Code sieht zur Zeit so aus:
Code: |
30 4 * * * root /mysqlimport/oracle2mysql 2>&1 >/var/log/oracle2mysql/log
|
nun will ich gerne das log File eindeutig benennen. Momentan behelfe ich mir noch unschön damit indem ich es am Ende der Batchdatei einfach mit einem DateTimeStamp versehe und umbenenne, weil alle Versuche das mittels
Code: |
$(date +%Y%m%d%H%M%S)
|
direkt im Cron Job anzupassen leider fehlgeschlagen sind.
Weiß wer von Euch wie sich das realisieren lassen könnte?
Vielen Dank schon mal für Eure Mithilfe und noch einen schönen Tag,
Andreas.
[/quote] _________________ Registered Linux User 371244
Last edited by andreas2000 on Mon Jan 17, 2005 9:12 am; edited 1 time in total |
|
Back to top |
|
 |
toralf Developer


Joined: 01 Feb 2004 Posts: 3943 Location: Hamburg
|
Posted: Thu Jan 13, 2005 4:25 pm Post subject: |
|
|
/bin/date anstelle date verwenden, da der cron die Umgebung und damit Pfade nicht kenn1 ?
Obige Zeile war Quatsch, ich denke, Du kanst im crontab keine 'dynamischen' Befehlszeilen einbauen. Von den nachfolgenden beiden Einträgen funktioniert halt nur der erste :
Code: |
$> crontab -l
* * * * * /bin/date > /tmp/test &
* * * * * /bin/date > /tmp/test_`/bin/date +%Y%m%d%H%M%S` &
|
Last edited by toralf on Thu Jan 13, 2005 4:34 pm; edited 1 time in total |
|
Back to top |
|
 |
Anarcho Advocate


Joined: 06 Jun 2004 Posts: 2970 Location: Germany
|
Posted: Thu Jan 13, 2005 4:27 pm Post subject: |
|
|
Das dürfte daran liegen das cron den befehl nicht im kontext einer bash ausführt und daher keine variablen kennt. Schreibt dir ein script welches dann
befehl >> /var/log/$(date +...) beinhaltet und rufe das per cron auf. wenn in der ersten zeile
#!/bin/bash
steht wird das mit der bash ausgeführt und sollte klappen _________________ ...it's only Rock'n'Roll, but I like it! |
|
Back to top |
|
 |
Fauli l33t


Joined: 24 Apr 2004 Posts: 760 Location: Moers, Germany
|
Posted: Fri Jan 14, 2005 8:10 pm Post subject: |
|
|
@andreas2000: Hast du man 5 crontab nicht gelesen?
Quote: | The ``sixth'' field (the rest of the line) specifies the command to be run. The entire command portion
of the line, up to a newline or % character, will be executed by /bin/sh or by the shell specified in
the SHELL variable of the cronfile. Percent-signs (%) in the command, unless escaped with backslash
(\), will be changed into newline characters, and all data after the first % will be sent to the command
as standard input.
|
|
|
Back to top |
|
 |
andreas2000 Tux's lil' helper


Joined: 02 Nov 2004 Posts: 144 Location: Austria/Vienna
|
Posted: Mon Jan 17, 2005 9:16 am Post subject: |
|
|
...da sieht mans wieder: wer lesen kann ist klar im Vorteil... vielen Dank für den Hinweis mit der Manpage - das hat geholfen und nun funktionierts:
Code: |
* * * * * /mysqlimport/oracle2mysql 2>&1 >/var/log/oracle2mysql/log_$(/bin/date +\%Y\%m\%d\%H\%M\%S)
|
_________________ Registered Linux User 371244 |
|
Back to top |
|
 |
tam Guru


Joined: 04 Mar 2003 Posts: 569
|
Posted: Mon Jan 17, 2005 11:08 am Post subject: |
|
|
logrotate ist für solche Sachen auch praktisch |
|
Back to top |
|
 |
|