LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-18-2003, 04:38 PM   #1
zovres
Member
 
Registered: Sep 2002
Posts: 184

Rep: Reputation: 30
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
 
Old 08-18-2003, 04:53 PM   #2
Mathieu
Senior Member
 
Registered: Feb 2001
Location: Montreal, Quebec, Canada
Distribution: RedHat, Fedora, CentOS, SUSE
Posts: 1,403

Rep: Reputation: 46
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
 
Old 08-18-2003, 04:54 PM   #3
Hangdog42
LQ Veteran
 
Registered: Feb 2003
Location: Maryland
Distribution: Slackware
Posts: 7,803
Blog Entries: 1

Rep: Reputation: 416Reputation: 416Reputation: 416Reputation: 416Reputation: 416
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.
 
Old 08-18-2003, 04:57 PM   #4
v3rb0
Member
 
Registered: Jun 2003
Location: Europe, Latvia
Distribution: Slackware
Posts: 44

Rep: Reputation: 15
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!

Last edited by v3rb0; 08-18-2003 at 05:12 PM.
 
Old 08-18-2003, 04:59 PM   #5
BenCarlisle
LQ Newbie
 
Registered: Feb 2003
Distribution: RH7,RH8,Slack
Posts: 29

Rep: Reputation: 15
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.....
 
Old 08-19-2003, 01:14 AM   #6
zovres
Member
 
Registered: Sep 2002
Posts: 184

Original Poster
Rep: Reputation: 30
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
a script that runs wget every 3 minutes Menestrel Programming 3 07-26-2005 12:22 PM
logout after script runs bigdog0007 Linux - Newbie 6 06-24-2005 06:42 PM
howto run a script from cron every 5 minutes except 11pm-8am ? cccc Programming 2 03-20-2005 04:52 AM
creating shell script that executes as root regardless of who runs the script? m3kgt Linux - General 13 06-04-2004 11:23 PM
Where can I the script that runs the forum? patpawlowski LQ Suggestions & Feedback 5 03-17-2004 05:37 PM


All times are GMT -5. The time now is 08:54 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration