Skip to content

Instantly share code, notes, and snippets.

@tzkmx
Created July 6, 2015 16:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tzkmx/1b499765e3cfea9e8eb9 to your computer and use it in GitHub Desktop.
Save tzkmx/1b499765e3cfea9e8eb9 to your computer and use it in GitHub Desktop.
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)
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment