PDA

View Full Version : [ubuntu] [SOLVED] Script to run two commands at once



askander
September 24th, 2008, 05:16 PM
Hi!

I Installed a program using wine an it runs flawlessly, but to use it, I need to execute a mount instruction in terminal, I know there's a way to make an script that mounts the folder I want and then start the application without touching the terminal, but I don't know how to do it.... any help? :confused:

Paqman
September 24th, 2008, 05:17 PM
How to write a simple bash script (http://floppix.ccai.com/scripts1.html)

anotherdisciple
September 24th, 2008, 05:21 PM
I rarely use wine, so I can't help you there... but to run two commands at once you need to send them to the background with (&).

This would open gimp and firefox at the same time:

firefox &
gimp &

This would attempt to delete a file... and if it was sucessful... it will delete anotherfile:


sudo rm /path/to/file && sudo rm /path/to/another/file

Titan8990
September 24th, 2008, 05:21 PM
A shell script like that is very easy to make. Scripts always begin with a "shebang" to tell the shell what interpreter to use.

Make a text file in an easy to find directory:


#!/bin/bash

COMMAND1
COMMAND2
COMMAND3

Use the shebang line that I have given. Replace COMMAND1 and etc with the command you would like the script to run.

Save the text file and then you have to make it executable. For this I will assume that the the file is called "test.sh". To make it executable:

chmod 775 test.sh

Then you can run the script:

./test.sh

Good luck!

anotherdisciple
September 24th, 2008, 05:24 PM
A shell script like that is very easy to make. Scripts always begin with a "shebang" to tell the shell what interpreter to use.

Make a text file in an easy to find directory:


#!/bin/bash

COMMAND1
COMMAND2
COMMAND3

Use the shebang line that I have given. Replace COMMAND1 and etc with the command you would like the script to run.

Save the text file and then you have to make it executable. For this I will assume that the the file is called "test.sh". To make it executable:

chmod 775 test.sh

Then you can run the script:

./test.sh

Good luck!

Yes, but the next command can't start until the other command is finished. So, you may need to do this.


#!/bin/bash

COMMAND1 &
COMMAND2 &
COMMAND3

askander
September 25th, 2008, 05:58 PM
I did it! Thanks all for your help! :)

Titan8990
September 25th, 2008, 06:02 PM
Good to hear. Don't forget to mark this thread as solved.