[python] bash script do Pythonu
starenka .
starenka0 na gmail.com
Úterý Září 30 13:42:22 CEST 2014
btw ten strftime neni v tomhle pripade treba, ale chtel sem ti ukazat,
jak si to naformatovat. tohle je taky uplne to samy:
>>> file = 'maillog-%s' % yesterday
>>> file
'maillog-2014-09-29'
s
---
In Perl you shoot yourself in the foot, but nobody can understand how
you did it. Six months later, neither can you. | print
'aknerats'[::-1]
2014-09-30 13:40 GMT+02:00 starenka . <starenka0 at gmail.com>:
> Ahoj, vcera udelas jednoduse za pomoci timedelta
>
>>>> import datetime
>>>> yesterday = datetime.date.today() - datetime.timedelta(days=1)
>>>> yesterday
> datetime.date(2014, 9, 29)
>>>> file = 'maillog-%s' % yesterday.strftime('%Y-%m-%d')
>>>> file
> 'maillog-2014-09-29'
>
>
> https://docs.python.org/2/library/datetime.html#timedelta-objects
>
> s.
> ---
> In Perl you shoot yourself in the foot, but nobody can understand how
> you did it. Six months later, neither can you. | print
> 'aknerats'[::-1]
>
>
> 2014-09-30 13:22 GMT+02:00 zu1234 <zu1234 at seznam.cz>:
>> Tohle by nepomohlo:
>>
>> Formatting “yesterday's” date in python
>> http://stackoverflow.com/questions/1712116/formatting-yesterdays-date-in-python
>>
>>
>>
>> Dne 30.9.2014 13:09, jenda.zakransky at gmail.com napsal(a):
>>
>>> Ahoj mam nize jednoduchy skript v bashi, ktery bych potreboval prevest do
>>> Pythonu, uz tomu venuji nejaky cas, ale proste to nejde a nejde, bylo by
>>> mozne nekoho poprosit o pomoc, moc dekuji
>>>
>>> Cilem tohoto skriptu je prevedeni a poslani message log filu z predesleho
>>> dne z jednoho serveru na druhy, tzn. ze dnes budu prevadet full daily log z
>>> predesleho dne.
>>>
>>> Originalni logy jsou v teto podobe ulozeny /opt/log/maillog-20140929.
>>> Tento log se diky skriptu nejdrive kopiruje prejmenovany z podoby
>>> maillog-20140929 na hostname.vcerejsidatum.gz do directory /tmp.
>>>
>>> Odtud dochazi ke kopirovani na remote server taktez do directory
>>> /opt/log/maillog a po zkopirovani je soubor z directory /tmp smazan.
>>>
>>> Nejvetsi problem mi dela zadani promenne, ktera ma v bashi nasledujici
>>> podobu fdate=$(date +%Y%m%d -d "-1 day") # vcerejsi datum - promenna fdate
>>> se odkazuje na vcerejsi den.
>>>
>>> HOTOVO
>>>
>>> #!/bin/bash
>>>
>>> path=/opt/log #jsem tedy v directory /opt/log
>>> fdate=$(date +%Y%m%d -d "-1 day") # vcerejsi datum
>>> file=maillog-$fdate # log file ze vcerejska ktery
>>> se bude prenaset
>>> cp $path/$file /tmp/$HOSTNAME-$file #zkopci $file do tempu pod novym
>>> jmenem; systemova promenna $HOSTNAME obsahuje hostname, tak neni treba
>>> vytvaret novou promennou
>>> gzip /tmp/$HOSTNAME-$file # zabali log,
>>>
>>> rserver=user at remoteserver.edu # remote server
>>> rpath=/opt/log/maillog # remote path
>>>
>>> scp /tmp/$HOSTNAME-$file.gz $rserver:$rpath # zkopiruje na remote server
>>> do remote path
>>>
>>> rm /tmp/$HOSTNAME-$file.gz # uklidi po sobe
>>> #hotovo
>>
>> _______________________________________________
>> Python mailing list
>> python at py.cz
>> http://www.py.cz/mailman/listinfo/python
>>
>> Visit: http://www.py.cz
Další informace o konferenci Python