5

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)

3 Answers 3

6

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.

1
  • +1, unless you have a specific reason to use &&, this is better.
    – user606723
    Aug 4, 2011 at 17:05
3

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

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

1
  • 1
    You can separately save the stdout of each with normal bash redirection: command1 > afile && command2 > anotherfile
    – kyleN
    Aug 4, 2011 at 16:28
1

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

You must log in to answer this question.

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