How to make shell commands when initializing an instance for automation

How to make shell commands when initializing an instance for automation

I would like to make an .sh script so that when when reactivating/initializing an instance it exectues the script.

How can I make it or where should I put the script?