Yes, that should work. In addition to the above script you're using we strongly recommend that you set a cronjob for the root user which has,
*/5 * * * * iptables -F
This will flush the iptables rules after every 5 minutes so even if you lock out of the server due to a bad iptables rule, the rules will be flushed every 5 minutes and you should be able to gain entry via SSH.
This is a much better way of deploying iptables and retaining access in case of a mistake and when the server is miles away in a data center.