How to avoid running duplicated task?

Hi Gurus,

I have requirement to run different task based on input value. the sample file as below:
file1 (contains code need to be run)

 
code
aaa1
aaa2
bbb
ccc
ddd

file2 (contains all codes and job name)

 
code job1  job2
aaa1, job_aa1, job_a2
aaa2, job_aa2, job_a2
aaa3, job_aa3, job_a2
bbb, job_bb1, job_b2
ccc, job_cc1, job_c2
...

the code I wrote as below:

 
#!/bin/ksh
IFS=','
egrep -f file1 file2 > runautojob.txt
        while read feed job1 job2
        do
        if [ $1 = 'job1_cnd' ]; then
        echo "here will be autosys command to start autosys job, job name is " $job1
        elif
          [ $1 = 'job2_cnd' ]; then
        echo "here will be autosys command to start autosys job, job name is " $job2
        elif [ $1 = 'job3_cnd' ]; then
        echo "here will be autosys command to start autosys job, job name is " $job3
        fi
        done<runautojob.txt

My problem is for same prefix (example aaa), I only need to run job2 once.
for example
file1 has code as below:
aaa1
aaa2
I can only run job_a2 once, but my current script runs twice.

I changed file2 as below

 
code job1  job2
aaa1, job_aa1, job_a2
aaa2, job_aa2, 
aaa3, job_aa3, 
bbb, job_bb1, job_b2
ccc, job_cc1, job_c2
...

but if the file1 like below, it failed again.

 
aaa2
aaa3

anybody can give me some idea to resolve this issue?

thanks in advance.

You can run 'fuser' on the executable file to see who is running it.

Hi DGPickett

thanks for your reply

I am not sure if you were answering my question. my problem is to avoid to run same process mulitiple times. not to find who is running the process.

thanks.

And the first step of doing that could be...

If it is running, then there is a pid on stdout, and a new run will be a duplicate. By tying stdout to stderr, you can get the letters that say it is being run (not just viewed or whatever) (fuser puts pids and separating white space on stdout and all else on stderr).

$ fuser bin/u_inetd
bin/u_inetd:    24702mt
$ ps -fp 24702
      UID   PID  PPID  C    STIME TTY       TIME COMMAND
 myid     24702     1  0  Aug 28  ttyp5     0:00 u_inetd 9090 http2env /home/myid/myweb
$

You can write the job's pid in a control file named for the job, and search for a running copy that way, but fuser is cleaner and simpler. Binding a socket can be exclusive, too.

I got you mean.

I will try it and let you know.

thanks