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)

Jiew Meng
  • 10,677

3 Answers3

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.

psusi
  • 38,031
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

danjjl
  • 6,573
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

user606723
  • 1,802