I'm working on a script to automate some stuff. The catch with this script is that if any action fails, it needs to "rollback" all the actions it just performed.
After thinking for a bit, I thought instead of having a billion if statements, I would put each command into an array:
Then I could run them in sequence. I would then make another array which had the expected string so I can check against it and see if it worked or not:
Then I could also have an array of rollback actions to run.
So, to run this I would just loop through CMD and for each action, make sure it's response was EXPECTED, and if not, I stop calling commands and then go back through ROLLBACK in reverse order starting at the index of the last good command.
Does anyone see a problem with this plan? More importantly, does anyone know a better way to do this?