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
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.
- 38,031
Write the commands with && between them eg : command1 && command2
Note : the second command won't be executed if the first command returns an error
- 6,573
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
- 1,802