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.

Is there a simple way for me to add a shell command to a list of jobs to have run on the system when I'm not logged in?

For example:

I SSH into my system, decide that I want to read an ebook later, but it's in the wrong format. I'll use Calibre to convert it, but this will take up the CPU for many minutes. I'm in no rush though, so I would like to tell my system to start the Calibre convert operation (just running a shell command) as soon as I log out of my SSH session. Then later when I SSH in again, my converted book will be waiting for me.

share|improve this question

migrated from serverfault.com Aug 9 '11 at 22:02

This question came from our site for professional system and network administrators.

add comment

3 Answers 3

up vote 3 down vote accepted

A simple, but possibly inconvenient method is to start the command with nohup to detach it from the terminal, just before logging out.

nohup mycommand &
logout

Any output from the command is sent to the file nohup.out in the current directory.

It is usually more convenient to run the command inside screen or tmux. Both programs provide a terminal within a terminal, and you can detach your session from the current terminal and reattach to it later.

screen
# inside the screen session
sleep 60; mycommand
# press Ctrl+A D to detach from the session
# now back in the original shell
logout

Then later:

screen -rd
# inside the screen session, you can see how your command is doing
…
exit

Another possibility is to schedule the job for later. The at command lets you schedule a job at a specific time (it's the once-off pendant of cron for regularly scheduled tasks). If the command produces output, it'll be mailed to you (assuming you have local mail running).

echo 'mycommand' | at 23:05
share|improve this answer
add comment

I'd just start a screen (nowadays accessed as 'byobu'), or tmux session. Do your stuff, and start the process, then disconnect. The job will continue to run, an when you are ready, you can reconnect, and get back into the session. I've had screen sessions running for months, and they can be pre-configured so that wneh

share|improve this answer
add comment

Use the at command to submit a batch job for processing. It won't wait for you to logout before running it though, so when you submit the job just make sure it's niceed.

share|improve this answer
add comment

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.