0

I will be running some batch process on Amazon EC2 Ubuntu 12 machines. I can log in using putty, run the command. The process will run for a day or two. There is a chance the putty will get disconnected. However I need the program keep running on the remote Ubuntu machine. Is it possible?

Like Windows RDP, log in to a machine, start some app, disconnect, come back later, app is still running. Similar experience in Ubuntu, how can I get? Thank you.

Thanks/.

7
  • 1
    If you are running telnet, you're in BIG trouble. Please use ssh! Feb 22, 2014 at 5:55
  • @DeerHunter I don't believe it's possible to get into an EC2 instance with telnet, but i can't explain why the question includes it.
    – Rob M
    Feb 22, 2014 at 6:32
  • 1
    why not install cron jobs on your 12 machines and let cron run your commands for you? Feb 22, 2014 at 6:39
  • @RedCricket That seems like an awfully roundabout way of just executing something in the background
    – Rob M
    Feb 22, 2014 at 7:03
  • 1
    @Robbie how so? opening up putty or a windows C:\> and then executing putty then login in to 12 different boxes and running a command seem far more "roundabout" then have a simple cron job on each of the boxes. I guess to some people setting up a cronjob is difficult. To each his own I guess. Feb 22, 2014 at 7:18

2 Answers 2

6

Screen. You will probably need to install it with apt-get install screen or similar, but once you have it, it's quite straight forward. Use screen to start it, and you will be given a bash or sh shell, use that to run your batch job, then use Ctrl+A followed by Ctrl+D to detach from the session. You may then log out, and can reattach at any time using screen -r. See man screen for more information. You could also simply fork the job to the background with an ampersand, ./job.sh &, but you will not be able to reattach to it at some later point in time.

3
  • 1
    Tmux is far more flexible than screen IMHO, but they both get the job done. Feb 22, 2014 at 5:12
  • I'll have to check that out
    – Rob M
    Feb 22, 2014 at 5:14
  • By the way, Screen is already installed on the default Amazon EC2 AMI. They must realize it's useful ;) Jun 18, 2014 at 4:59
6

use nohup and & with your command / batch process. RUn you script or command like below

  nohup command &

even your putty session disconnect your command will continue to run in background.

Not the answer you're looking for? Browse other questions tagged .