[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [Sheflug] Running programs on file creation
>
> I've looked at it, and it isn't quite what I want. The
> problem is that we've
> only got one phone line, and my modem is quite stubborn about
> such things as
> detecting dial tones(It dials if someone's using the phone :( ). Also,
> because of some of the programs that are run on the network(e.g. MSN
> Messenger) it's going to be trying to connect to the net the
> whole time(If
> I've read things correctly that is :)
> --
This may sound stoopid (!), but how about a simple PERL script (or similar)
which polls your /var/lock/connect directory, but more frequently than cron
would? How about this as a starter?
#!/usr/bin/perl -w
while (1) {
sleep(5);
opendir DIRECTORY,"locks/";
@dir = readdir DIRECTORY;
foreach $dir ( [at] dir) {
if (($dir ne ".") and ($dir ne "..")) {
print "found file $dir so execute a program and
restart\n";
system("ps");
last;
}
}
closedir DIRECTORY;
}
Ok, I'm not the world's greatest PERL hacker. Someone will probably show you
a better way of testing for "." and ".." using pattern matching, but it
works...
The 'system("ps")' could be whatever you need to do to connect. Just make
sure you remove the thing that caused the script to fire off a connection in
the first place otherwise 5 seconds later, it will reconnect again!
Having just re-read your original email, this would work with a few extra
tweaks. What you'd get with this approach that a simple cron job won't give
you is you have an opportunity to maintain the state of the program between
polls. That means you can remember that you're connected and that when the
file disappears, you have to drop the connection.
system() will suspend your script whilst the other program runs. I can't,
off the top, find a way of running the second program concurrently. It's
probably something to do with fork, but it's not something I've ever done
before.
Anyone else help?
--
David Morris
work: david [at] allvac.co.uk
home: david [at] brassedoff.net
http://www.davidm.demon.co.uk
___________________________________________________________________
Sheffield Linux User's Group - http://www.sheflug.co.uk .
To unsubscribe from this list send mail to
shef-lug-request@list.sheflug.org.uk with the word
"unsubscribe" in the body of the message.
GNU the choice of a complete generation.