Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Suppose I have jobs to run one after another, how can I queue them up and if possible still retain the output/log each script produces. (eg. I can use at to schedule tasks but I dont get the log/output of each app)

share|improve this question

3 Answers 3

up vote 2 down vote accepted

If you want to run several commands interactively, just separate them with a semicolon:

foo ; bar ; baz

If you want to queue a batch of commands to be executed in the background when the system isn't too busy and possibly after you have logged out, you can use the batch command. The output of jobs run with batch, at, or cron is emailed to you. For that to work, you need to setup a local mail server.

share|improve this answer
    
+1, unless you have a specific reason to use &&, this is better. –  user606723 Aug 4 '11 at 17:05

Write the commands with && between them eg : command1 && command2

Note : the second command won't be executed if the first command returns an error

share|improve this answer
1  
You can separately save the stdout of each with normal bash redirection: command1 > afile && command2 > anotherfile –  kyleN Aug 4 '11 at 16:28

If this is a long list of commands, or you're going to do this often enough, I would make a script to do it for you.

shell scripts of this nature are extremely easy.

#!/bin/bash
foo
bar
baz

Simply put this text into a file, turn execution on (chmod +x myscript) and then ./myscript and off you go.

This will execute commands foo, bar, and baz in order assuming that all of them block.

If you ever want to do something more complicated see the Advanced Bash-Scripting Guide

share|improve this answer

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.