Auto-terminate instance from shell

Is it possible to make an instance auto-terminate with a command? Like for example when the model is finished training I would like to have it dump the model & reports & whatever else to somewhere else via sftp and then terminate the instance automatically