Umgebungsvariable aus AWK-Skript setzen
Hallo zusammen,
ich habe ein kleines AWK-Skript gebastelt, welches mir zur aktuellen Systemzeit die Vorstunde (+Vortag und Vormonat bei Tageswechsel)
liefert. Als Newbie stehe ich nun vor dem Problem, dass ich aus dem Skript heraus das Ergebnis von LASTHOUR, LASTDAY.... an das
aufrufende Batchfile zurückliefern möchte, am besten als Umgebungsvariable. Und da steh ich gerade auf dem Schlauch....
Das Skript:
BEGIN {
CURRENTSYSTIME=systime()
CURRENTDATE=strftime("%Y-%m-%d", CURRENTSYSTIME)
CURRENTYEAR=strftime("%y", CURRENTSYSTIME)
CURRENTMONTH=strftime("%m", CURRENTSYSTIME)
CURRENTDAY=strftime("%d", CURRENTSYSTIME)
CURRENTHOUR=strftime("%H", CURRENTSYSTIME)
LASTHOURSYSTIME=systime()-3600
LASTHOURDATE=strftime("%Y-%m-%d", LASTHOURSYSTIME)
LASTYEAR=strftime("%y", LASTHOURSYSTIME)
LASTMONTH=strftime("%m", LASTHOURSYSTIME)
LASTDAY=strftime("%d", LASTHOURSYSTIME)
LASTHOUR=strftime("%H", LASTHOURSYSTIME)
print CURRENTHOUR,CURRENTDAY,CURRENTMONTH,CURRENTYEAR
print LASTHOUR,LASTDAY,LASTMONTH,LASTYEAR
}
Danke im Voraus,
freude
ich habe ein kleines AWK-Skript gebastelt, welches mir zur aktuellen Systemzeit die Vorstunde (+Vortag und Vormonat bei Tageswechsel)
liefert. Als Newbie stehe ich nun vor dem Problem, dass ich aus dem Skript heraus das Ergebnis von LASTHOUR, LASTDAY.... an das
aufrufende Batchfile zurückliefern möchte, am besten als Umgebungsvariable. Und da steh ich gerade auf dem Schlauch....
Das Skript:
BEGIN {
CURRENTSYSTIME=systime()
CURRENTDATE=strftime("%Y-%m-%d", CURRENTSYSTIME)
CURRENTYEAR=strftime("%y", CURRENTSYSTIME)
CURRENTMONTH=strftime("%m", CURRENTSYSTIME)
CURRENTDAY=strftime("%d", CURRENTSYSTIME)
CURRENTHOUR=strftime("%H", CURRENTSYSTIME)
LASTHOURSYSTIME=systime()-3600
LASTHOURDATE=strftime("%Y-%m-%d", LASTHOURSYSTIME)
LASTYEAR=strftime("%y", LASTHOURSYSTIME)
LASTMONTH=strftime("%m", LASTHOURSYSTIME)
LASTDAY=strftime("%d", LASTHOURSYSTIME)
LASTHOUR=strftime("%H", LASTHOURSYSTIME)
print CURRENTHOUR,CURRENTDAY,CURRENTMONTH,CURRENTYEAR
print LASTHOUR,LASTDAY,LASTMONTH,LASTYEAR
}
Danke im Voraus,
freude
Please also mark the comments that contributed to the solution of the article
Content-Key: 93623
Url: https://administrator.de/contentid/93623
Printed on: April 24, 2024 at 06:04 o'clock
2 Comments
Latest comment
So weit ich das verstehe können mit AWK keine Informationen direkt an eine Systemvariable übergeben werden. Zum anderen ist es sogar nicht möglich die Informationen zuerst in eine Variable zu schieben, damit diese von einer anderen Anwendung gefressen wird. Vielleicht könnte das alles als Oneliner funktionieren, leider habe ich wenig Zeit zum testen.
Also hier meine Vorschlag.
script.awk=======
BEGIN {
CURRENTSYSTIME=systime()
CURRENTDATE=strftime("%Y-%m-%d", CURRENTSYSTIME)
CURRENTYEAR=strftime("%y", CURRENTSYSTIME)
CURRENTMONTH=strftime("%m", CURRENTSYSTIME)
CURRENTDAY=strftime("%d", CURRENTSYSTIME)
CURRENTHOUR=strftime("%H", CURRENTSYSTIME)
LASTHOURSYSTIME=systime()-3600
LASTHOURDATE=strftime("%Y-%m-%d", LASTHOURSYSTIME)
LASTYEAR=strftime("%y", LASTHOURSYSTIME)
LASTMONTH=strftime("%m", LASTHOURSYSTIME)
LASTDAY=strftime("%d", LASTHOURSYSTIME)
LASTHOUR=strftime("%H", LASTHOURSYSTIME)
print "set today = "CURRENTHOUR,CURRENTDAY,CURRENTMONTH,CURRENTYEAR
print "set yesterday = "LASTHOUR,LASTDAY,LASTMONTH,LASTYEAR
}
cvars.cmd=======
awk -f script.awk > make.cmd
make
del make.cmd >NUL
Das ganze dann mit einem weiteren Aufruf innerhalb Deiner Batch.
Schau Dir ansonsten das hier mal an
Bye
MT
Also hier meine Vorschlag.
script.awk=======
BEGIN {
CURRENTSYSTIME=systime()
CURRENTDATE=strftime("%Y-%m-%d", CURRENTSYSTIME)
CURRENTYEAR=strftime("%y", CURRENTSYSTIME)
CURRENTMONTH=strftime("%m", CURRENTSYSTIME)
CURRENTDAY=strftime("%d", CURRENTSYSTIME)
CURRENTHOUR=strftime("%H", CURRENTSYSTIME)
LASTHOURSYSTIME=systime()-3600
LASTHOURDATE=strftime("%Y-%m-%d", LASTHOURSYSTIME)
LASTYEAR=strftime("%y", LASTHOURSYSTIME)
LASTMONTH=strftime("%m", LASTHOURSYSTIME)
LASTDAY=strftime("%d", LASTHOURSYSTIME)
LASTHOUR=strftime("%H", LASTHOURSYSTIME)
print "set today = "CURRENTHOUR,CURRENTDAY,CURRENTMONTH,CURRENTYEAR
print "set yesterday = "LASTHOUR,LASTDAY,LASTMONTH,LASTYEAR
}
cvars.cmd=======
awk -f script.awk > make.cmd
make
del make.cmd >NUL
Das ganze dann mit einem weiteren Aufruf innerhalb Deiner Batch.
Schau Dir ansonsten das hier mal an
Bye
MT
Noch was vergessen, das hier im Abschnitt Yesterday könnte auch interessant sein, obwohl es auf der Seite auch ein schickes Perl Script gibt, was auch den Zweck erfüllen würde.