寻求类Liquibase的非数据库工具:仅执行更新后的bat脚本
Great question! When you're dealing with a large library of .bat scripts and need to avoid re-running unchanged ones during production releases, there are several mature tools and patterns that mirror Liquibase's change-tracking approach but focus on file/script execution instead of databases. Here are my top recommendations:
1. Ansible (Configuration Management Tool)
Ansible is perfect for this use case because it excels at state tracking. You can:
- Use the
statmodule to capture the checksum or last modified time of each.batscript. - Compare this value against a stored state (either in Ansible facts, a local tracking file, or even a simple text inventory).
- Only execute the script if the checksum has changed (indicating the script was updated or is new).
- Bonus: Ansible automatically logs execution details, making audits easy, and you can integrate it into your CI/CD pipeline seamlessly.
2. Custom Batch/Shell Wrapper Script
If you prefer a lightweight, no-external-dependency solution, build a simple wrapper:
- Maintain a tracking file (e.g.,
script_execution_history.txt) that stores each script's filename and its SHA-256 hash. - For each
.batscript in your deployment directory:- Calculate its hash using Windows built-in tools like
certutil -hashfile "script.bat" SHA256. - Check if the hash exists in the tracking file.
- If it's missing or different, run the script and update the tracking file with the new hash.
- Calculate its hash using Windows built-in tools like
- This is ideal for small teams or environments where heavy tools aren't necessary—just make sure the tracking file is persisted between deployments.
3. Rundeck (Automation Orchestration Platform)
Rundeck is designed for managing and auditing automated tasks, including script execution. You can:
- Create a job that scans your
.batscript directory. - Use Rundeck's built-in file comparison features or custom scripts to detect new/updated files.
- Configure the job to only execute scripts that have changed since the last run.
- Benefit from Rundeck's dashboard, which gives you visibility into execution history, logs, and status—great for teams that need centralized oversight.
4. SaltStack (Configuration Management & Remote Execution)
Similar to Ansible, SaltStack lets you track file states and trigger actions based on changes:
- Use the
file.checksumfunction to get the hash of each.batscript. - Store known good hashes in Salt Grains or Pillar data.
- Set up a state that executes the script only when the current hash doesn't match the stored value.
- SaltStack is especially powerful if you already use it for infrastructure management, as it integrates seamlessly with existing workflows.
5. Chef (Configuration Management)
Chef uses a "resource-based" model that's perfect for state tracking:
- Define a
fileresource for each.batscript, which monitors its checksum. - Use the
notifiesdirective to trigger anexecuteresource (running the script) only when the file's checksum changes. - Chef automatically maintains a local state cache, so it knows exactly when a script has been modified and needs to be re-run.
Key Best Practices to Follow
- Ensure all your
.batscripts are idempotent: Meaning running them multiple times won't cause unintended side effects. This is a safety net in case tracking logic ever fails. - Keep detailed execution logs: Whether using a tool's built-in logging or custom log files, you'll want to trace which scripts ran and when for debugging and compliance.
- Test in staging first: Validate your tracking logic in a non-production environment before rolling it out to PROD to catch any edge cases.
内容的提问来源于stack exchange,提问作者Aleksey Panin

