I have a script that will take around 10-15 hours to complete. I want to run it on EC2 instance and after say 10 hours stop the process forever.
Approaches--
CRONTAB
-if I make a cronjob for the process . How to ensure it runs only once in lifetime and delete after 10 hour?
To do this, in your buildspec, use the nohup command to run a command as a task in the background, even if the build process exits the shell. Use the disown command to forcibly stop a running background task. Start a background process and do not wait for it to ever complete: nohup sleep 30 & disown $!
Connect using a standalone SSH client. Connect using Session Manager. Connect using browser-based SSH connection.
When you stop an EC2 instance, the instance will be shutdown and the virtual machine that was provisioned for you will be permanently taken away and you will no longer be charged for instance usage.
You need to open a screen session. You can do this by typing screen
in the bash prompt. Once you have fired in your command, type Ctrl-a
followed by d
. This will detach your screen session. However the script that you run will continue to run.
Now, you can disconnect from your ssh session. And once you log back in, you can resume
your session by typing in screen -r
. This is assuming that you have only one detached
session. In case you have more than one, you will have to type in the pid of the session you want to attach back to.
To check the pid
of the session, you can do:
ps aux | grep screen
This will list out the currently running screen processes. A sample output is:
dhanush 1327 0.0 0.0 2443312 56 s000 S+ 3Sep15 0:00.99 screen -r server -p server
dhanush 79037 0.0 0.0 2432784 600 s008 S+ 5:03PM 0:00.00 grep screen
Here the pid
for the relevant screen process is 1327
.
The second line belongs to the grep
command that searched for the keyword screen
itself.
tmux is another alternative for the same.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With