Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

NFS Watcher

by penguinfuz (Pilgrim)
on May 16, 2002 at 13:13 UTC ( #167001=sourcecode: print w/replies, xml ) Need Help??
Category: Utility Scripts
Author/Contact Info penguinfuz at gmail dot com
Description: I wrote this script to address an issue I had with Apache authentication and multiple load-balanced web servers, and I run it from a cronjob every so often.

Basically I keep ONE copy of the relevent .htaccess files and NFS export their location to the other web servers in the cluster.

I am sure this script could be extended further, but I have not messed with it since it serves the basic purpose I started towards. I hope someone else will find this code useful as well. ;)

Added "use strict;" and found a missing semicolon at: my $ip_add = ""
And a global @mntargs; hanging around.
#! /usr/bin/perl -w

use strict;

my $thisdir     = "/path/to/thisdir";
my $thatdir     = "/path/to/thatdir";
my $ip_add      = "";
my @mntargs;

if (!(-d "$thisdir")) {
  @mntargs = ("/bin/mount", "${ip_add}:$thisdir", "$thisdir");
  print "Mounting ${ip_add} for CC-Proc1 .htpasswd access...\n";
  system (@mntargs);
  if (!(-d "$thisdir")) {

if (!(-d "$thatdir")) {
  @mntargs = ("/bin/mount", "${ip_add}:$thatdir", "$thatdir");
  print "Mounting ${ip_add} for CC-Proc2 .htpasswd access...\n";
  system (@mntargs);
  if (!(-d "$thatdir")) {

sub email_error {
  my $ip_add = shift;
  my $hostname = `/bin/hostname`;
  open(SENDMAIL, "|/usr/lib/sendmail -oi -t")
    or die "Cannot fork for sendmail: $!\n";

  print SENDMAIL <<EOF;
From: NFS Watcher <root\@${hostname}>
To: System Admin <penguinfuz\@anotherdomain.dom>
Subject: Something is broken with the NFS mount!

This email is generated by the NFS Watcher script on $hostname...

I noticed the NFS export from ${ip_add} was NOT mounted, but
whenever I tried mounting it, something didn't work.
Remember, until the NFS export from ${ip_add} is properly mounted,
the .htpasswd authentication will not work %100!


  close(SENDMAIL) or warn "Oops, sendmail did not close nicely\n";
Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://167001]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (10)
As of 2018-06-22 14:12 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (124 votes). Check out past polls.