Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm new to Linux, and I'm probably asking a fairly basic question. How do I run a continuous program on Linux?

Basically, I have a program that will continuously check for content on a website. This program will be executing for several days. I do not have administrative privileges on the computer I wish to run this program on, and I do not have exclusive access to this computer either, meaning that other users can log on physically. Moreover, barring some untold disaster, the computer will be running for the entire duration of my program.

I know that I can SSH into the machine and run the program. However, this is not desirable as I would need a second machine to do it (which kind of defeats the point of what I'm doing), not to mention timeout issues.

Is there a way I can run my program on the computer remotely without establishing a connection of some sort after I get it started?

share|improve this question

3 Answers 3

up vote 12 down vote accepted

If it is something that needs to happen at regularly scheduled intervals use cron( e.g. you need to check the website once every hour, or once every day, or more or less frequently than that but still not arbitrarily defined).

However... You may want to run a command at a cerain later time rather than right now, for that you want to use the at daemon, which allows you to run a command once at a later date/time (like it's 5 o'clock and you want to go home but you've got a 4 hour process that would be best run in the middle of the night, and it's not reoccurring).

I will say nohup, screen , tmux have been mentioned, use nohup if you want to run it right now but don't want to reconnnect to that session to check on it later. screen/tmux are for checking on it later.

share|improve this answer

You need to do two things:

  1. Run the command with nohup. This stops the remote machine from terminating the command when you disconnect
  2. Run the command in the background, by appending &. This isn't strictly necessary, but will return you to a shell instead of blocking on the command so you can disconnect normally or do other things

So for the command command:

nohup command &
share|improve this answer

nohup is definitely the right way to go if you can run your program without interacting with it: if it writes all its output and error messages into a file that you can get to later, for instance. check the nohup.out file to see any error messages the program left behind while running (thanks for the correction, Michael!)

If you need to interact with the program while it's running, GNU Screen might be the better way to go about it. It lets you create a virtual terminal which remains running even after you log out, along with any programs you started in it, as long as nobody shuts the computer down. Here's a tutorial I found on using it.

share|improve this answer
2  
nohup will actually write stdout to nohup.out by default, but definitely screen is better for interactive programs –  Michael Mrozek Aug 23 '10 at 6:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.