I very often automate tasks using bash, a Makefile, or some other means. By far the best advice I can give anyone is to make your tasks idempotent. Let me say that again:
make your tasks idempotent
Having said that, it can be difficult when there are sub-tasks that should only be run once. Here is my small life-hack around that:
- check for the existence of a dot-file, e.g.
.db-create-tables
- if the dot-file does not exist, run the task and pipe the output to
.db-create-tables.tmp
- upon success, and only on success,
mv .db-create-tables.tmp .db.create-tables
This has the added benefit of being able to see the output of your various tasks, while also leaving a definitive marker of their success.