tzkmx
7/6/2015 - 4:42 PM

Creates empty log file dated using mysql output

Creates empty log file dated using mysql output

@ECHO OFF
REM mysql DATE_FORMAT tokens: %W (weekday name) %M (month name) %d (month day) %Y (year)
SET timeformatstring='%%W_%%M-%%d-%%Y'
REM FOR /F takes output from `time /t` and tokenizes it in %A %B and %C
FOR /F "usebackq tokens=1-4 delims=: " %%A IN (`time /t`) DO (
  REM takes localized output from mysql NOW() string built with tokens in %timeformatsring%
  FOR /F "usebackq tokens=1-2 skip=1 delims=| " %%H IN (`mysql -h %dbHost% -u %dbUser% -p%dbPass% -e "SET @@lc_time_names='es_MX'; SELECT UPPER(DATE_FORMAT(NOW(), %timeformatstring%));"`) DO (
    ECHO Creating log file with date: %%H and time: %%A%%B%%C
    REM CMD equivalent of Unix touch? http://superuser.com/a/764725
    TYPE NUL >> %%H_%%A%%B%%C && COPY %%H_%%A%%B%%C +,,
    REM (TYPE NULL create empty file && COPY _ +,, update timestamp)
  )
)