Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > How Do I Use CGI->System Call As CronJob?

Reply
Thread Tools

How Do I Use CGI->System Call As CronJob?

 
 
Public Interest
Guest
Posts: n/a
 
      10-31-2003
I got shell access, but not cronjob access. I want to use a CGI to start the
job, and use either a html refresh or a task in windows as the cronjob
starter.

In fact, I can even use cgi to change the refresh rate according to
conditions set in perl script.

My only problem is my JOB takes too much time to run: Job A takes10 minutes,
Job B takes 2-8 hours. The problem with CGI is that cgi has a lifetime of
180 seconds or so and it will be broken after that time. Here is what I want
to do:

Part1 Start a process which is then indepentant of the CGI, so even the CGI
is dead or finished, the new process is still running. Should I start a
child, a sys, an exec

Part2 Print running logs to a output file, and the output can be seen from
web. Part2 is easy, but if I want to print the file into an absolute dir,
should I use the absolute dir of webspace under apache or abs dir under
shell? such as which to call dir1/dir3/html/ from dir1/dir2/cgi-bin/?
html,
/html,
.../dir3/html
/dir1/dir2/html



 
Reply With Quote
 
 
 
 
Anno Siegel
Guest
Posts: n/a
 
      10-31-2003
Public Interest <(E-Mail Removed)> wrote in comp.lang.perl.misc:
> I got shell access, but not cronjob access. I want to use a CGI to start the
> job, and use either a html refresh or a task in windows as the cronjob
> starter.
>
> In fact, I can even use cgi to change the refresh rate according to
> conditions set in perl script.
>
> My only problem is my JOB takes too much time to run: Job A takes10 minutes,
> Job B takes 2-8 hours. The problem with CGI is that cgi has a lifetime of
> 180 seconds or so and it will be broken after that time. Here is what I want
> to do:
>
> Part1 Start a process which is then indepentant of the CGI, so even the CGI
> is dead or finished, the new process is still running. Should I start a
> child, a sys, an exec


If that is meant to be a question it doesn't make much sense. Starting
a child is what you are talking about. "Starting a sys" or "an exec"
doesn't have a recognized meaning.

If you are asking whether you should start the child via exec() or via
system() (not to mention other alternatives), that is a secondary point.
Depending on details of the background job and its communication needs,
one or the other method may be more practical.

> Part2 Print running logs to a output file, and the output can be seen from
> web. Part2 is easy, but if I want to print the file into an absolute dir,


There is no such thing as an "absolute directory". There are directories
(and files) which you can *access* through an absolute or relative
path name.

> should I use the absolute dir of webspace under apache or abs dir under
> shell?


What is the difference? Is the web server running in a chroot environment?
Otherwise, an absolute path is an absolute path, for a shell just like
for apache.

> such as which to call dir1/dir3/html/ from dir1/dir2/cgi-bin/?
> html,
> /html,
> ../dir3/html
> /dir1/dir2/html


Since you (reasonably) want to use an absolute path, the first and third
alternatives are out -- they are relative paths. Why are you mentioning
them? The other two are absolute paths, but only one will address the
directory you want. Use the one that addresses the directory you want.
(The last one looks most plausible, but there is no way of telling.)

Anno
 
Reply With Quote
 
 
 
 
Public Interest
Guest
Posts: n/a
 
      10-31-2003
I guess I forgot to mention that in part1:

I think I should use exec(), but I need to CD it first. But exec will leave
the CGI program, so how do I exec 2 things?

For example, I want to run
cd /home/mydir
sh something.sh

if I put
exec ('cd /home/mydir');
exec ('sh something.sh');

the first exec will have nothing to do with the second one. so should I use
system at the first then exec at the second one?


 
Reply With Quote
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      10-31-2003
Public Interest wrote:
> For example, I want to run
> cd /home/mydir
> sh something.sh
>
> if I put
> exec ('cd /home/mydir');
> exec ('sh something.sh');
>
> the first exec will have nothing to do with the second one.


Try

exec ('cd /home/mydir; sh something.sh');

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

 
Reply With Quote
 
Anno Siegel
Guest
Posts: n/a
 
      10-31-2003
Public Interest <(E-Mail Removed)> wrote in comp.lang.perl.misc:
> I guess I forgot to mention that in part1:
>
> I think I should use exec(), but I need to CD it first.


Why do you think you still need to change the directory? I thought
you were going to use absolute path names.

> But exec will leave
> the CGI program, so how do I exec 2 things?


You can only exec one thing. See "perldoc -f exec".

> For example, I want to run
> cd /home/mydir
> sh something.sh
>
> if I put
> exec ('cd /home/mydir');
> exec ('sh something.sh');
>
> the first exec will have nothing to do with the second one. so should I use
> system at the first then exec at the second one?


Wouldn't help. "System" runs the "cd" in a forked process. See "perldoc
-f system". You really should have taken a look there before.

You can change the directory in the mother process before you exec. The
resulting process will inherit the working directory.

Anno
 
Reply With Quote
 
Public Interest
Guest
Posts: n/a
 
      10-31-2003
Another very very big problem:

The CGI still want for the exec to be finished!!!. I have printout from the
EXEC. and it kept showing on my browser!!!

So they are still not independent.

And only the Child's print is out and parent's output is not printed..

Try this: in test.cgi

#!/usr/bin/perl

print "Content-type: text/html\n\n";
exec ('sh test.sh);
print 'ok this is parent';

in test.sh:
ls -al


Then in my browser, it shows all the files, but no 'ok this is hte parent'.


 
Reply With Quote
 
Captain Dondo
Guest
Posts: n/a
 
      10-31-2003
Public Interest wrote:
> The CGI still want for the exec to be finished!!!. I have printout from the
> EXEC. and it kept showing on my browser!!!


man bash:

exec If command is specified, it replaces the shell.

When you run 'exec', there is no longer a script to return to. exec is
the last command any script will run.

If you want to return to it, use 'system'.

I'm guessing that perl and sh are consistent in the use of 'exec' and
'system'.

-Dondo

--
What am I on?
I'm on my bike, o__
6 hours a day, busting my ass. ,>/'_
What are you on? --Lance Armstrong (_)\(_)

 
Reply With Quote
 
Anno Siegel
Guest
Posts: n/a
 
      10-31-2003
Public Interest <(E-Mail Removed)> wrote in comp.lang.perl.misc:
> Another very very big problem:
>
> The CGI still want for the exec to be finished!!!. I have printout from the
> EXEC. and it kept showing on my browser!!!
>
> So they are still not independent.


That is because the child's STDOUT is the same as the parent's. If you
don't want to see output, re-direct it in the child process.

> And only the Child's print is out and parent's output is not printed..
>
> Try this: in test.cgi
>
> #!/usr/bin/perl
>
> print "Content-type: text/html\n\n";
> exec ('sh test.sh);
> print 'ok this is parent';
>
> in test.sh:
> ls -al
>
>
> Then in my browser, it shows all the files, but no 'ok this is hte parent'.


Of course it doesn't. Would you *please* take a look at the documentation
of the functions you're using? A successful call to exec() does *not*
return to the calling process. If you want that, use system().

Anno
 
Reply With Quote
 
Public Interest
Guest
Posts: n/a
 
      10-31-2003
Because I want the Child to be seperated and totally independent from
Parent, so system does not work for me. I want both child and parant to live
and run until finish. I want something like & in shell

ls &

How do I have a & in perl?


> Public Interest wrote:
> > The CGI still want for the exec to be finished!!!. I have printout from

the
> > EXEC. and it kept showing on my browser!!!

>
> man bash:
>
> exec If command is specified, it replaces the shell.
>
> When you run 'exec', there is no longer a script to return to. exec is
> the last command any script will run.
>
> If you want to return to it, use 'system'.
>
> I'm guessing that perl and sh are consistent in the use of 'exec' and
> 'system'.
>
> -Dondo
>
> --
> What am I on?
> I'm on my bike, o__
> 6 hours a day, busting my ass. ,>/'_
> What are you on? --Lance Armstrong (_)\(_)
>



 
Reply With Quote
 
David Efflandt
Guest
Posts: n/a
 
      10-31-2003
On 31 Oct 2003, Anno Siegel <(E-Mail Removed)-berlin.de> wrote:
> Public Interest <(E-Mail Removed)> wrote in comp.lang.perl.misc:
>> Another very very big problem:
>>
>> The CGI still want for the exec to be finished!!!. I have printout from the
>> EXEC. and it kept showing on my browser!!!
>>
>> So they are still not independent.

>
> That is because the child's STDOUT is the same as the parent's. If you
> don't want to see output, re-direct it in the child process.


In other words look for daemonize in 'perldoc perlipc'. It shows how to
fork a child and disassociate itself from the parent (your CGI). Of
course your CGI should provide some proper output to either just
acknowledge, or advise the browser if the fork fails.

Once you fork the child and disassociate it from the parent, it could run
your 2 other processes.

--
David Efflandt - All spam ignored http://www.de-srv.com/
http://www.autox.chicago.il.us/ http://www.berniesfloral.net/
http://cgi-help.virtualave.net/ http://hammer.prohosting.com/~cgi-wiz/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Call Manager limit call duration nazgulero Cisco 0 10-25-2005 06:58 AM
RMI: remote call or local call Buu Nguyen Java 5 09-17-2004 08:05 AM
help: need to call call web service from java bill sandner Java 1 07-01-2004 02:57 PM
Use a Perl_Interpreter and NOT call it my_perl? Use TWO interpreters? Torsten Mohr Perl Misc 6 12-31-2003 01:56 AM



Advertisments