How to avoid running duplicated task?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to avoid running duplicated task?
# 1  
Old 01-07-2015
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:
 
code
aaa1
aaa2
bbb
ccc
ddd

file2 (contains all codes and job name)
Code:
 
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:
Code:
 
#!/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:
 
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.
Code:
 
aaa2
aaa3

anybody can give me some idea to resolve this issue?

thanks in advance.

Last edited by ken6503; 01-07-2015 at 05:32 PM..
# 2  
Old 01-07-2015
You can run 'fuser' on the executable file to see who is running it.
# 3  
Old 01-07-2015
Quote:
Originally Posted by DGPickett
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.
# 4  
Old 01-07-2015
Quote:
Originally Posted by ken6503
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...
# 5  
Old 01-07-2015
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).
Code:
$ 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.
# 6  
Old 01-07-2015
Quote:
Originally Posted by DGPickett
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).
Code:
$ 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

Last edited by ken6503; 01-08-2015 at 10:35 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Avoid running unnecessary repetitive ps command

i have the following code: APIDS=$(echo $(ps -ef | awk -v gpid="${gpid}" '$2 == gpid || $3 == gpid {print $2,$3}') | sed 's~ ~|~g') AllProcs=$(ps -ef | awk -v allpids="${APIDS}" '$2 ~ allpids || $3 ~ allpids {print $0}' | sed '/^$/d') it seems the above... (6 Replies)
Discussion started by: SkySmart
6 Replies

2. Shell Programming and Scripting

Running the calling script/task as per day

Hello all.. i have few task to do on specific day ar per weekday or weekend... for example i have 3 tasks: task1 task2 task3 Now i need to create a shell script If it is weekday it will change the status of these tasks as below sendevent -E CHANGE_STATUS -s SUCCESS -J task1... (4 Replies)
Discussion started by: j_panky
4 Replies

3. UNIX for Dummies Questions & Answers

Duplicated UID

Hi folks! I need you help to discover what's the impact of a duplicated UID in an operating system. What's the meaning when someone put in different users the same UID? (3 Replies)
Discussion started by: phcostabh
3 Replies

4. Shell Programming and Scripting

Help with remove duplicated content

Input file: hcmv-US25-2-3p hsa-3160-5 hcmv-US33 hsa-47 hcmv-UL70-3p hsa-4508 hcmv-UL70-3p hsa-4486 hcms-US25 hsa-360-5 hcms-US25 hsa-4 hcms-US25 hsa-458 hcms-US25 hsa-44812 . . Desired Output file: hcmv-US25-2-3p hsa-3160-5 hcmv-US33 hsa-47 hcmv-UL70-3p hsa-4508 hsa-4486... (3 Replies)
Discussion started by: perl_beginner
3 Replies

5. Shell Programming and Scripting

Avoid script running multiple times by filelock

Sometimes we need a single instance of a script to run at a time. Meaning, the script itself should detects whether any instances of himself are still running and act accordingly. When multiple instances of one script running, it’s easy to cause problems. I’ve ever seen that about 350 instances... (4 Replies)
Discussion started by: edenCC
4 Replies

6. Shell Programming and Scripting

Parse an XML task list to create each task.xml file

I have an task definition listing xml file that contains a list of tasks such as <TASKLIST <TASK definition="Completion date" id="Taskname1" Some other <CODE name="Code12" <Parameter pname="Dog" input="5.6" units="feet" etc /Parameter> <Parameter... (3 Replies)
Discussion started by: MissI
3 Replies

7. Shell Programming and Scripting

comment and Uncomment single task out of multiple task

I have a file contains TASK gsnmpproxy { CommandLine = $SMCHOME/bin/gsnmpProxy.exe } TASK gsnmpdbgui { CommandLine = $SMCHOME/bin/gsnmpdbgui.exe I would like to comment and than uncomment specific task eg TASK gsnmpproxy Pls suggest how to do in shell script (9 Replies)
Discussion started by: madhusmita
9 Replies

8. UNIX for Advanced & Expert Users

Can root ID be duplicated

Hi, I have the root id and the uid is always 0 for the root. Can i create another user say admin with the uid as 0? If so will it have the same privilege as that of user. Will there be any effect while doing this? lorcan (6 Replies)
Discussion started by: lorcan
6 Replies

9. UNIX for Dummies Questions & Answers

Running UNIX commands remotely in Windows box from Unix box – avoid entering password

I am able to run the UNIX commands in a Windows box from a UNIX box through "SSH" functionality. But whenever the SSH connection is established between UNIX and Windows, password for windows box is being asked. Is there a way to avoid asking password whenever the SSH connection is made? Can I... (1 Reply)
Discussion started by: D.kalpana
1 Replies

10. Shell Programming and Scripting

killing and relaunching a task every 15 minutes while a script is running

Hi there, I would like to write a script which while running will kill and then execute again a task every 15 minutes. Here's what I want to do: Al Jazeera English have a low quality, time-limited 15 minute trial stream up at their site. I.e. when I click on the 56K link, it will play in... (0 Replies)
Discussion started by: ropers
0 Replies
Login or Register to Ask a Question