Run several commands at a time


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Run several commands at a time
# 1  
Old 08-24-2008
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!
# 2  
Old 08-24-2008
Quote:
Originally Posted by agasamapetilon
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..
# 3  
Old 08-24-2008
You can also use something like:
Code:
(command1 &) ; (command2 &) ; (command3 &)

This will launch every command into the background and execute all at the same time (barely).
# 4  
Old 08-24-2008
Thanks for the answers guys Smilie

I have the following code for an example as a reference:
Code:
(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! Smilie

Last edited by agasamapetilon; 08-24-2008 at 08:27 PM..
# 5  
Old 08-24-2008
Quote:
Originally Posted by redoubtable
You can also use something like:
Code:
(command1 &) ; (command2 &) ; (command3 &)

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

There is no need for the subshells:
Code:
command1 & command2 & command3 &

Or:
Code:
command1 &
command2 &
command3 &

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Run 2 exec commands

I have to create two instances of jBoss 5.1.0 GA. In order to do that I have to execute the following in start-jboss.sh: find . -exec /opt/novell/idm/jboss/bin/run.sh -Djboss.service.binding.set=ports-01 -c IDMProv -b 0.0.0.0 \; -exec /opt/novell/idm/jboss/bin/run.sh... (4 Replies)
Discussion started by: Joydeep Ghosh
4 Replies

2. UNIX for Dummies Questions & Answers

To run 5 commands at the same time with process from a list

I have many command is list in the variable lists,each command will run a very long time, so I want to run 5 commands at the same time with process till it complete run all the command, lists="aa bb cc dd xx gg blabla zz ......." ( a very long list) can some one point me the codes? ... (7 Replies)
Discussion started by: yanglei_fage
7 Replies

3. Shell Programming and Scripting

Script to run commands at a specific time.

Hello All, I have written a script which which is working fine to a certain logic of it. But i want a part of the script to run two commands at 00:10 hrs every day. These two command are 1. rm -rf /path/to/folder 2. mail the content of a file. How do i achieve this. Thanks. ... (4 Replies)
Discussion started by: Siddheshk
4 Replies

4. UNIX for Dummies Questions & Answers

Run multiple commands

Hi All, Is it possible to run second/multiple commands at a time in script before the completion/return of first command? Pls reply. (5 Replies)
Discussion started by: cns1710
5 Replies

5. HP-UX

Unable to run some commands in HP-UX

Hi All, I want to get %cpu and %memory utilization for a given process id in HP-UX so am using the following commands 1)TOP -p <PID> am getting error message like Quitting top: pset 26323 doesn't exist,but when am using only TOP command without any options its working fine. 2)ps -e -o pcpu... (5 Replies)
Discussion started by: Ramya_Nm
5 Replies

6. Shell Programming and Scripting

Run a shell script from one host which connext to remote host and run the commands

I want to write a script which would run from one host say A and connect to other remote host B and then run rest of commands in that host. I tried connecting from A host to B with SSH but after connecting to host B it just getting me inside Host B command prompt. Rest of the script is not running... (6 Replies)
Discussion started by: SN2009
6 Replies

7. UNIX for Dummies Questions & Answers

Cannot run commands

It would be helpful if someone could help me out here. The problem I have been having is that I cannot run some commands which are valid - whenever I try to run the command I get the message "command not found". Now, if I run the same command as root it executes. These commands do not have to be... (5 Replies)
Discussion started by: BigTool4u2
5 Replies

8. Shell Programming and Scripting

run commands from a variable

I have a question of how to run commands from a variable where there are more than one commands in the variable under bash. I ran the following commands under bash > command="ls /etc/zshrc; ls /etc/zshenv" > $command The results were: ls: /etc/zshrc;: No such file or directory ls: ls:... (1 Reply)
Discussion started by: pankai
1 Replies

9. UNIX for Dummies Questions & Answers

run commands before login

What would be the best way to setup for a Linux box to run a few commands before the user logs in? (1 Reply)
Discussion started by: woofie
1 Replies

10. IP Networking

Run commands on a UNIX with NT

Hi I'm trying to automatically run a command on a UNIX (AIX) machine from a Windows NT 4 machine. I can do this manually using the 'rexec' or 'rsh' command but I need an automatic login (on the AIX). In the manual I've found that there should be a '.rhosts' file on the Unix machine in the... (1 Reply)
Discussion started by: Mark Detrez
1 Replies
Login or Register to Ask a Question