Jea, thats it! Thats exactly what i had in mind! 

Thank you very much! This List and it´s members are excellent!

Greets Johannes

-----Ursprüngliche Nachricht-----
Von: Robin Cragg [mailto:[EMAIL PROTECTED]]
Gesendet: Montag, 30. September 2002 15:10
An: Theuerkorn Johannes
Betreff: Re: AW: how to know weather perl script is already running?


Hi,

firstly, the problem with your script is most likely that your path is 
wrong (don't forget the `` or system open a shell and then run the command. 
That means you should try to specify all the patsh in your command line. 
Secondly, I would not use grep if I were you.

ps -wfaux | grep myproc

will produce two lines. The first is myprog, the second is \_ grep 
myprog.  :-)  Linux is cute like that. It's much simpler to do it all in 
PERL. I would do the PS too, but I've not seen a module for it yet. This 
code works.


open PS, "/bin/ps -wwfaux |";
@PS = <PS>;
close PS;

my $flag = 0;

foreach (@PS) {
         $flag++ if (/$0/);
}


die "$0: Process already running!\n" if ($flag > 1);

while (1) {
         sleep 10;
}

It's also neater to use $0 so you can change your script name.


R


At 14:35 30/09/2002 +0200, you wrote:
>Hi Robin, that was the way i wanted to do it, but i got problems with it. I
>tried to use:
>
>#!/bin/sh
>if ! [`ps ax|grep "perl /home/user1/DiREx/generate_database/"`]
>then `scripttorun`
>fi
>
>but it returns the following error:
>
>./call_script: [23038: command not found
>
>It seems to use the returned process id as command...
>
>So how to write such a script?
>
>Greets Johannes
>
>-----Ursprüngliche Nachricht-----
>Von: Robin Cragg [mailto:[EMAIL PROTECTED]]
>Gesendet: Montag, 30. September 2002 14:25
>An: Theuerkorn Johannes; '[EMAIL PROTECTED]'
>Betreff: Re: how to know weather perl script is already running?
>
>
>There are two easy ways...
>
>
>If your file creates a lock file when it starts and removes it when it
>finishes, a chec to see if the file exists will tell you if the script is
>already running./
>
>On linux / unix systems do a ps and looks for any occurrances of your
>script name. If there are more than one, then die....
>
>
>R
>
>
>At 11:18 30/09/2002 +0200, Theuerkorn Johannes wrote:
> >Hello List,
> >
> >i have a perl script that i have running from a cron Job. It usually opens
> >every 4 hours. But sometimes it takes the script longer to execute its job
> >so after cron opens up the perl script as usual, i have two perl jobs
>running.
> >Is there any possibility to check weather the script is already running?
> >Maybe i can use a system command in the crontab?
> >
> >any help welcoe
> >
> >greets Johannes
> >
> >--
> >To unsubscribe, e-mail: [EMAIL PROTECTED]
> >For additional commands, e-mail: [EMAIL PROTECTED]

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to