Shell scripts with sequential input files in background

There are 3 scripts, expA, expB ,and expC on my Linux server (Ubuntu 12.04 LTS). Then , I got 32 input files named as nctu_0, nctu_1 ..... nctu_31. Six of them are much larger them others, so I take 3 input files for expA, 3 for expB, and the other for expC.

i.e. expA: run nctu_6 nctu_13 nctu_17 ,expB: run nctu_20 nctu_24 nctu_31 ,expC: run the other files

Here is the original script of expB, and the script of expA is almost the same as expB

#!/bin/bash
PROGRAM=./Simulator
FILE_PART_PREFIX1=/home//data/pcap_partial/h1200/nctu_
RESULT_PREFIX1=/home/data/setup_exp/h1200
RECEIVER_SIZE=4096
SENDER_SIZE=4096
BETA=0.25
UPDATE=400
MARKER=20
part=20
if [ ${part} -eq 20 ];then
nohup ${PROGRAM} 1 ${FILE_PART_PREFIX1}${part}.pcap ${RECEIVER_SIZE} ${SENDER_SIZE}    ${BETA} ${UPDATE} ${MARKER} ${MODE} >> ${RESULT_PREFIX1}/res_${part} 2>&1 &
fi
part=24
if [ ${part} -eq 24 ];then
nohup ${PROGRAM} 1 ${FILE_PART_PREFIX1}${part}.pcap ${RECEIVER_SIZE} ${SENDER_SIZE}   ${BETA} ${UPDATE} ${MARKER} ${MODE} >> ${RESULT_PREFIX1}/res_${part} 2>&1 &
fi
part=31
if [ ${part} -eq 31 ];then
nohup ${PROGRAM} 1 ${FILE_PART_PREFIX1}${part}.pcap ${RECEIVER_SIZE} ${SENDER_SIZE} ${BETA} ${UPDATE} ${MARKER} ${MODE} >> ${RESULT_PREFIX1}/res_${part} 2>&1 &
fi

I want to run nctu_20 first, then run nctu_24 after nctu_24 is done. At last run nctu_31 after nctu_24 is done.


Here is the original script of expC

#!/bin/bash
PROGRAM=./Simulator
FILE_PART_PREFIX1=/home/data/pcap_partial/h1200/nctu_
RESULT_PREFIX1=/home/data/setup_exp/h1200
RECEIVER_SIZE=4096
SENDER_SIZE=4096
BETA=0.25
UPDATE=400
MARKER=20
for (( part=0;part<32;part=part+1 ))
do
if [ ${part} -eq 6 ] || [ ${part} -eq 13 ] || [ ${part} -eq 17 ] || [ ${part} -eq 20 ] ||[ ${part} -eq 24 ] || [ ${part} -eq 31 ];then
continue
else
nohup ${PROGRAM} 1 ${FILE_PART_PREFIX1}${part}.pcap ${RECEIVER_SIZE} ${SENDER_SIZE} ${BETA} ${UPDATE} ${MARKER} ${MODE} >> ${RESULT_PREFIX1}/res_${part} 2>&1 &
fi
done

In brief, I want to run expA, expB expC at the same time and each of them launch a simulator program with a sequential input file in the background. Can someone help me?

Answers


I'm not sure that I've understood well what you need, but if you want to run them simultaneously, I don't think bash can help you. You should write a wrapper in some other languages that supports threads, here is in example in perl:

#!/usr/bin/perl
use strict;
use warnings;
use threads;

sub start_simulator {
   my $simulator = shift;
   system("./$simulator");
}

my $thA = threads->create('start_simulator', 'expA');
$thA->detach();

my $thB = threads->create('start_simulator', 'expB');
$thB->detach();

my $thC = threads->create('start_simulator', 'expC');
$thC->detach();

exit 0;

Add this wrapper inside the same directory where you have your shell script and run it with ./perl_wrapper.pl.


Need Your Help

Shows too many arguments for method

scala slick-2.0

I am trying to insert few data in apple_reportDB but I get the error as Too many arguments for method in the insert query

Xml file reading by its node c#

c# asp.net .net xml webforms

i want to read a XML file and then show it to the webpage but i am unable to do it in for loop

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.