My ex-boss created a Rube Goldberg machine of a set of batch scripts. These scripts download log files from s3 using s3cmd, split said files based on information contained within using LogParser and LogParser SQL, convert one of the split logs into a csv using LogParser and more LogParser SQL, and finally updates a MS SQL server using that csv, LogParser, and another application of LogParser SQL. Each of these separate steps is a different .bat controlled with a different Windows scheduled task. One of your steps didn't complete in time? Too bad! He saw no problem with any of this.
Given I have called this person my ex-boss and I'm currently complaining about his code, you can probably make two guesses - 1, this eldritch machination doesn't work anymore, and 2, I (and another team member) are tasked with fixing it. You would be correct.
My team uses Linux at work, so I didn't get to just modify the bat scripts and sql files with new paths, etc. Instead, I got to toss out the bats, rewrite the relevant portions in bash, update all of the sql files with correct paths, and then get LogParser running in Wine as it's the only program fit for the task. I've not been allowed to rewrite by the new big boss, however - this isn't a new feature and the old code "works" so he can't sell it as a sexy new thing to the people who pay us. We're just finding out what's wrong with the code (hint: it's the entire first paragraph) and fixing it. My compatriot and I may just say screw it and rewrite it behind his back.
Quick primer on batch files: You either can't easily reuse code or he didn't know how. That means stuff like the following is duplicated across every single .bat file (and, surprisingly, was not miscopied or modified in any of them so they all function more or less the same).
:GetMyTimeStamp
:: Subroutine to get timestamp for output log files, in order to isolate files compressed by gzip
FOR /f "tokens=1-4 delims=/ " %%i IN ("%date%") DO (
SET dow=%%i
SET month=%%j
SET day=%%k
SET year=%%l
)
FOR /f "tokens=1-4 delims=.: " %%i IN ("%time%") DO (
SET hour=%%i
SET minute=%%j
SET second=%%k
SET hundredth=%%l
)
IF %hour% LSS 10 SET hour=0%hour%
SET MyTimeStamp=%year%%month%%day%%hour%%minute%%second%
GOTO:EOF
It has since been replaced with the following in my new and improved bash script:
MyTimeStamp=$(date +"%y%m%d%H%M%S")
It's not exactly equivalent, but it's close enough. I mean it's still horrible and we can't wait until we redo it the right way, but I'll take the latter over the former any day of the week. You ever have to figure out what "SET thing=%otherthing:~-6%" does without having access to a Windows command prompt? I did, and it required some careful Googling.