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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
08-18-2003, 03:38 PM
|
#1
|
Member
Registered: Sep 2002
Posts: 184
Rep:
|
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 
|
|
|
08-18-2003, 03:53 PM
|
#2
|
Senior Member
Registered: Feb 2001
Location: Montreal, Quebec, Canada
Distribution: RedHat, Fedora, CentOS, SUSE
Posts: 1,403
Rep:
|
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
|
|
|
08-18-2003, 03:54 PM
|
#3
|
LQ Veteran
Registered: Feb 2003
Location: Maryland
Distribution: Slackware
Posts: 7,803
|
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.
|
|
|
08-18-2003, 03:57 PM
|
#4
|
Member
Registered: Jun 2003
Location: Europe, Latvia
Distribution: Slackware
Posts: 44
Rep:
|
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 04:12 PM.
|
|
|
08-18-2003, 03:59 PM
|
#5
|
LQ Newbie
Registered: Feb 2003
Distribution: RH7,RH8,Slack
Posts: 29
Rep:
|
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.....
|
|
|
08-19-2003, 12:14 AM
|
#6
|
Member
Registered: Sep 2002
Posts: 184
Original Poster
Rep:
|
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 07:51 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|