A question about plugins

I want to add my own shutdown script, which I usually add to cron. Can I add it as a plugin instead? When plugins are added, do they just get run once? do they keep getting run one after another as an endless loop? Are they only run under other circumstances?
Thanks!