Script not checking previous instance run


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script not checking previous instance run
# 1  
Old 06-17-2012
Tools Script not checking previous instance run

Hi All,

I have developed Smilie a script that should run only if previous instance has stopped .
But illogically Smilie my script runs even if previous instance is running .I am not sure Smilie what is going wrong Smilie , please help.

Code:
#!/bin/ksh
HOME=/fs159/Purgingbackup/UPW/Purging
SCRNAME=`basename $0.ksh`

#Run the backup 
RunBackup()
{
    cd $HOME
    echo $$ > $HOME/${SCRNAME}.run
    java -Xms262144K -Xmx524288K -jar "Backup_Purge8_4thApr.jar" backup
}

#Check if previous instance of the script for supplied request ID is still running
if [ -s $SCRNAME.run ];
then
    ps -p `cat $HOME/${SCRNAME}.run` > /dev/null
    if [ $? -eq 0 ];
    then
        echo "$0 is already running...terminating current run"
        echo "$0 Utility Ends -  " `date '+%m/%d/%y %H:%M:%S'`
        echo "================================================"
        exit 0
    else
        echo "RUN file for the script was pending but the script was not running...deleted RUN file"
        rm -f $HOME/${SCRNAME}.run
    fi
fi

RunBackup

Please help me.Smilie.

Last edited by pludi; 06-17-2012 at 07:32 AM..
# 2  
Old 06-17-2012
Are you sure the script is still running in background when you trigger it again?

It seems to be working fine on my system (I substituted the java command with an infinite loop to test it)
# 3  
Old 06-18-2012
Full path? There is no "cd" before the "if" test. Also lose the trailing semi-colon on this and the other "if" test.
Code:
if [ -s $HOME/$SCRNAME.run ]

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

To trigger script on particular instance

Hi Guys, I have a main_script.sh which runs every day and scheduled in crontab. in the main script i read data from config file test.config apple mango orange main_script.sh for i in `cat test.config` do if then echo 'Apple' (3 Replies)
Discussion started by: Master_Mind
3 Replies

2. Shell Programming and Scripting

Loop to run commands - after the previous instance completed

Hi All, I am trying to call a shell script in a loop. I want my first instance to complete, and then the 2nd instance of the command to start - and so on. eg. I am running this script 30 times. The wrapper script needs business date, from_time,to_time & server_name as inputs. script_name... (2 Replies)
Discussion started by: neil.k
2 Replies

3. Shell Programming and Scripting

Making sure only one instance of a script is running

so i have a script that takes a while to complete and its cpu intensive. this script is being used by several users. i want to make sure only 1 user can run this script at any given time. i originally thought of running a while loop to egrep the process table of the PID ($$) of the process,... (7 Replies)
Discussion started by: SkySmart
7 Replies

4. Shell Programming and Scripting

A script that spawns multiple instance of itself.

Hi all,I have some questions of forking new process,the code is below.Any help will be appreciated. 1 #! /bin/bash 2 3 PIDS=$(pidof sh $0) 4 P_array=( $PIDS ) 5 echo $PIDS 6 let "instances = ${#P_array}-1" 7 8 echo "$instances instance(s)" of this script running." 9... (4 Replies)
Discussion started by: homeboy
4 Replies

5. Shell Programming and Scripting

Help with multiple instance script checking

I am trying to debug the following script. It appears that when the check for script running occurs, it's finding the actual grep statement and causing the script believe the script is already running. This is deployed on two different servers where one works fine, the other doesn't. Any ideas? ... (2 Replies)
Discussion started by: DaddyMoose
2 Replies

6. UNIX for Dummies Questions & Answers

KSH Checking Previous Date**

How would I go about getting the previous date on the server? I'm out of ideas...I am thinking that I could do it using the date command, but I am unable to find any information on doing it. For example if the current date is April 17th 2008 it would be (20080417) <- (YYYYMMDD). I need the previous... (4 Replies)
Discussion started by: developncode
4 Replies

7. Shell Programming and Scripting

replace first instance(not first instance in line)

Alright, I think I know what I am doing with sed(which probably means I don't). But I cant figure out how to replace just the first occurance of a string. I have tried sed, ed, and grep but can't seem to figure it out. If you have any suggestions I am open to anything! (3 Replies)
Discussion started by: IronHorse7
3 Replies

8. Shell Programming and Scripting

Shell to run one after another checking any flag or file

a.ksh & b.ksh run at the same time and takes huge resource and time.I want to put a technique so that one wil run after another. eg put a flag so that each script will check if it running , then sleep and wait it to finish. Can some one advise (3 Replies)
Discussion started by: konark
3 Replies

9. Shell Programming and Scripting

Error checking a file from previous file size

Hi, I'm currently trying to write a script that checks a log file for certain errors. Once checked it then records the filesize in another file. All this is fine, my problem is that the next time I do my error check I only want to check from previously recorded filesize to the end of file. I'm... (2 Replies)
Discussion started by: stuck1
2 Replies

10. UNIX for Dummies Questions & Answers

Can I use history command to run previous commands?

Hi, I can use history command in unix to view my last 50 commands. But how can I run the previous commands easily? Can history command help? Firebird (2 Replies)
Discussion started by: firebirdonfire
2 Replies
Login or Register to Ask a Question