Run several commands at a time

Hello guys, I am new at shell scripting and I want to create a script that runs several commands at a time, ie: uptime, w, df -h and so on and send the output of this commands to a text file so it can be send via email at a certain time using crontab.

Any help will be much appreciated!

all these commands should be run at a time??
use at command or run each command in background..

You can also use something like:

(command1 &) ; (command2 &) ; (command3 &)

This will launch every command into the background and execute all at the same time (barely).

Thanks for the answers guys :slight_smile:

I have the following code for an example as a reference:

(uptime &) ; (w &) ; (free &) > /home/my-dir/scripts/example.txt

I want to see in the example.txt the output of the uptime command, saying as a header: Server uptime... then two line breaks, another header should be diplayed and the output to the w command and so on... but at the shell I want nothing to be diplayed...

I hope to made myself clear with this, and thanks once more for your help! :slight_smile:

There is no need for the subshells:

command1 & command2 & command3 &

Or:

command1 &
command2 &
command3 &