Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

How can I run a script in multiple instances in Ubuntu server?

For example, I have a long running script named scanner.sh placed in /usr/bin/, which I wish to run the script in 10 parallel instances. How can I start the parallel tasks (and pass different flags / options / parameters to them)?

and how can I stop the instances?

share|improve this question

3 Answers 3

up vote 1 down vote accepted
#**parallel_scaller.sh**
# Script to async run scanner.sh
# USAGE: $> bash parallel_scanner.sh "FLAGS FOR INSTANCE 1" ... "FLAGS FOR INSTANCES 10"
$1=`echo $1 | sed 's/"//g'`
$2=`echo $1 | sed 's/"//g'`
$3=`echo $1 | sed 's/"//g'`
$4=`echo $1 | sed 's/"//g'`
$5=`echo $1 | sed 's/"//g'`
$6=`echo $1 | sed 's/"//g'`
$7=`echo $1 | sed 's/"//g'`
$8=`echo $1 | sed 's/"//g'`
$9=`echo $1 | sed 's/"//g'`
$10=`echo $1 | sed 's/"//g'`

bash scanner& $1 2>&1
bash scanner& $2 2>&1
bash scanner& $3 2>&1
bash scanner& $4 2>&1 
bash scanner& $5 2>&1
bash scanner& $6 2>&1
bash scanner& $7 2>&1
bash scanner& $8 2>&1
bash scanner& $9 2>&1
bash scanner& $10 2>&1

& places task in background. 2>&1 redirects STDOUT to STDERR.

To end the processes, type:

$> ps aux | grep scanner
$> kill $PIDS
share|improve this answer
    
Thanks. But how to stop specific instance? Also, the lines below should be: bash scanner.sh $1 2>&1, right ? –  Raptor Oct 3 '14 at 15:00

I'd like to propose you start using configuration management system like, preferrably Ansible.

It's written on Python, really easy-to-use for everyone, for newbies also.

Follow the docs http://docs.ansible.com/ and get started!

share|improve this answer

Besides the suggested answer, I use the following command:

nohup ./scanner.py -flag1 flag1value -flag2 flag2value &

to create a new instance. To view all running scanner.py instance, I use:

ps aux | grep scanner.py

To kill a specific instance, I use:

kill -9 {PID}

where {PID} is obtained from the ps aux command, e.g. kill -9 1234

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.