Google Answers Logo
View Question
 
Q: Automatic execution of perl scripts from Unix ( Answered 5 out of 5 stars,   0 Comments )
Question  
Subject: Automatic execution of perl scripts from Unix
Category: Computers > Programming
Asked by: tjsnod-ga
List Price: $10.00
Posted: 26 Sep 2002 10:21 PDT
Expires: 26 Oct 2002 10:21 PDT
Question ID: 69389
I have a Web site hosted on a Unix server to which I have SSH access. 
I have two perl scripts that generate the html for my site.  I would
like to set up the two scripts to execute every 15 minutes so that the
site is automatically updated.  What's the easiest way to do this?  I
began looking at a crontab, but it seemed like it could only be used
to execute on a fixed schedule.  Is there a simple way to just loop
execution commands with appropriate delays?  Thanks in advance!
Answer  
Subject: Re: Automatic execution of perl scripts from Unix
Answered By: voyager-ga on 26 Sep 2002 10:52 PDT
Rated:5 out of 5 stars
 
Hi tjsnod!

You already were on the right way! Crontab is indeed the solution to
your problem:

The best way to do it is if you create a file with the following
content:

0,15,30,45 * * * * /absolut_path/command

then do a crontab filename to activate the new crontab.

If you want to start your command every 15 minutes without having to
rely on cron, you still have multiple options. One would be the
following script (just cut&paste it into a file and start at any
time):

#!/bin/sh
while true
do
command
sleep 15m
done

I hope this helped! Should you require any further information, please
feel free to ask for clarification! If there are any problems with the
script or crontab, please tell me what kind of UNIX you are working
on.

Thank you for your question,

voyager-ga

Request for Answer Clarification by tjsnod-ga on 26 Sep 2002 13:35 PDT
actually, can i request a quick clarification on crontab?  when you
say create a file, then 'do a crontab filename to activate the new
crontab', I have no idea what the latter part means :)

when I do crontab -e, it creates my user account's crontab file, which
I can then save.  but how do i activate it exactly?  and also, once
it's going (since it's on a perpetual loop), how do I stop it? 
thanks!

Clarification of Answer by voyager-ga on 26 Sep 2002 16:42 PDT
Hi again tjsnod!

Thanks for the good rating!

By saying "do a crontab filename" I meant that to activate the new
crontab you just write

crontab filename

and thereby activate the program "filename".

A crontab -e is actually crontab in its "edit mode". You don't have to
create a file in that case. Crontab will just take your current
crontab file (which probably is empty at the moment) and present you
with it in your default editor (you can probably find you default
editor in the VISUAL or EDITOR environment variable - probably vi(m)
if you're working remotely). Once you save the crontab, it
automatically will be activated in that case.

Stopping a crontab command works the same way: 
Type "crontab -e"
delete the line with the command you don't want to be executed
anymore.
Save the file.
Done.

You can also just write "crontab -d" if you just want to delete your
current crontab, or do a "crontab filename" to replace it with another
crontab you created before.

As for killing the script I wrote - you can either start it in the
foreground and later kill it with a CTRL-c (and leave it e.g. in a
"screen" while you are offline) or you just do a
killall commandname
with commandname being the name of the script - only if the script is
the only thing running with that name though ... otherwise you'll have
to take a look at the processes first:
ps -ef |grep commandname
kill process_number_of_commandname

I hope this helps! Again - if you need further assistance, don't
hesitate to ask for clarification!

voyager-ga
tjsnod-ga rated this answer:5 out of 5 stars
thanks!

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy