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

Use a shell trap.

help trap / google / ai chatbot for more info

Try something like this…

# Your stuff ... snip ...

function post_training_cleanup()
{
  # You'll need to read the docs / tinker here..
  # But I imagine a shutdown or poweroff would be sufficient
  # Might require privilege escalation (sudo etc.)

  shutdown
}

function main()
{
  # ... Your setup stuff ...

  trap "post_training_cleanup ;" EXIT
}

#####

main "$@"