0 votes
1 view
in AWS by (18.2k points)

I set up RStudio Server on an Amazon EC2 instance, which is charged by the hour. I have to run long jobs overnight on this instance regularly. I would like to stop the EC2 server when my R job is done to avoid charges for the hours I don't use.

How should I go about this?

1 Answer

0 votes
by (42.4k points)

You can add your username and add NOPASSWD in the /etc/sudoers file. This will allow unsupervised action, for instance:

username ALL = NOPASSWD: /sbin/shutdown

halt the computer later with a system call like this:

system('sudo shutdown -h now', wait = FALSE)

...