LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   a script that runs every 5 minutes? (https://www.linuxquestions.org/questions/linux-newbie-8/a-script-that-runs-every-5-minutes-83222/)

zovres 08-18-2003 03:38 PM

a script that runs every 5 minutes?
 
is it possible to do a script that check a text file every five minutes, and if something is there, run a few commands?

thx :)

Mathieu 08-18-2003 03:53 PM

Yes.
Create your script.
And then using cron, you can schedule the script to run at specific times or intervals.


Automated Tasks
http://www.redhat.com/docs/manuals/l...autotasks.html

Hangdog42 08-18-2003 03:54 PM

Sure. If you can write the script you want, you just need to make it executable and set it up as a cron job. Have a look at the crontab manual entry to find out how to execute a program every five minutes.

v3rb0 08-18-2003 03:57 PM

yes,
try to, use crontab (see man pages, or look in this forum, there should be some discusion about it)
or make in script infinitive loop with `sleep 300` command to wait 5minutes and do those commands You need.
There is also such thing as `FAM` it use fs notifications to track the creation of file (maybe also the changes of file, i dunno, i read today in mailing list about it :) )
Perl module using FAM can be found here http://search.cpan.org/author/JGLICK...lib/SGI/FAM.pm

hope smth. will help!

BenCarlisle 08-18-2003 03:59 PM

Yep, sure is.

You have to first create the script to check for the existence of the file, and run the commands. If you're not familliar with shell scripting, here's a basic template (bash):


#!/bin/sh
TESTFILE="/tmp/runit.dat"

if [ -f ${TESTFILE} ]; then
command1
command2
command3
fi


This script will look for the file called /tmp/runit.dat and will execute command1, command2, and command3 in succession if the file does exist.

The next thing you have to do is schedule the script to run every 5 minutes in cron (if you're unfamilliar with cron, man cron provides documentation.

Basically you'll want to add a line to your crontab file. Edit your crontab file (see manpage), and add the following line anywhere in the file:


5 * * * * /your/new/script/filename


where the /your/new/script/filename is, obviously, the location of the script file you created above, and the number 5 means "run every 5 minutes".

Install the crontab (again, see manpage) and you're good to go!

hope this helps.....

zovres 08-19-2003 12:14 AM

coool!!! I managed to have everything working perfectly thanks to you guys!

I love you all, thx for your big help, the links and the basic scripting :)


All times are GMT -5. The time now is 03:28 PM.