Hi all,
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:Code:CMD[0]='command'; CMD[1]='command'; # ...
Then I could also have an array of rollback actions to run.Code:EXPECTED[0]='expected'; EXPECTED[1]='expected'; # ...
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.Code:ROLLBACK[0]='rollback'; ROLLBACK[1]='rollback'; # ...
Does anyone see a problem with this plan? More importantly, does anyone know a better way to do this?
Thanks.



Reply With Quote
Bookmarks